package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.*;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSON;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bifang.assistant.common.enums.ExcelTypeEnum;
import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.assistant.common.vo.OrderVO;
import com.bifang.assistant.common.vo.SessionInfo;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.annotation.SaveOplog;
import com.bifang.engine.assistant.core.enums.AuTypeEnum;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.jetcache.utils.JetCacheUtils;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.util.CommonSecureUtil;
import com.bifang.module.base.common.util.FieldChangeUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.DictQueryVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.excel.*;
import com.bifang.module.base.common.vo.oplog.ModifiedFieldVO;
import com.bifang.module.base.common.vo.oplog.RemoveField;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.helper.ExcelCommonHelper;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.system.common.enums.CardTypeEnum;
import com.bifang.module.system.core.dao.model.BusiFile;
import com.bifang.module.system.core.dao.model.ExcelModel;
import com.bifang.module.system.core.dao.model.ExcelParam;
import com.bifang.module.system.core.dao.model.PersonInfo;
import com.bifang.module.system.core.dao.service.*;
import com.bifang.module.system.core.integration.impl.ExcelIntegrationImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.common.AreaControlVO;
import com.jwsoft.manager.common.vo.eduBusiEnrollPre.EduBusiEnrollPreVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSchool.SchoolDistrictQueryVO;
import com.jwsoft.manager.common.vo.eduSchool.SchoolDistrictVO;
import com.jwsoft.manager.common.vo.eduSchoolVacancy.EduSchoolVacancyQueryVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.EduStudentEnrollVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollFamily.EduStudentEnrollFamilyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.*;
import com.jwsoft.manager.common.vo.student.StudentInfoSearchVO;
import com.jwsoft.manager.common.vo.student.StudentInfoSelectVO;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.*;
import com.jwsoft.manager.core.util.EduDesensitizeUtil;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

/**
 * 预采集表业务实现类
 *
 * @author wangtao
 * @since 2022-11-25
 */
@ApiService(funcCode = "edustudentenrollpre", title = "预采集管理")
public class EduStudentEnrollPreIntegrationImpl implements EduStudentEnrollPreIntegration {

    @Autowired
    public EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private RedisHelper redisHelper;
    @Autowired
    private EduStudentEnrollImitateService eduStudentEnrollImitateService;
    @Autowired
    public EduStudentEnrollFamilyService eduStudentEnrollFamilyService;

    @Autowired
    public ExcelModelService excelModelService;

    @Autowired
    public ExcelParamService excelParamService;

    @Autowired
    public SysDictService sysDictService;

    @Autowired
    ExcelCommonHelper excelCommonHelper;

    @Autowired
    private CommonIntegration commonIntegration;

    @Autowired
    EduSchoolService eduSchoolService;

    @Autowired
    PersonInfoService personInfoService;

    @Autowired
    EduBusiEnrollPreService eduBusiEnrollPreService;

    @Autowired
    public DictHelper dictHelper;
    @Autowired
    public DictIntegration dictIntegration;
    @Autowired
    public EduSystemConfigIntegration eduSystemConfigIntegration;

    @Autowired
    public ExcelIntegrationImpl excelIntegration;

    @Autowired
    private EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    private EduHouseholdService eduHouseholdService;
    @Autowired
    private EduComplaintService eduComplaintService;
    @Autowired
    private EduAddressSchoolService eduAddressSchoolService;
    @Autowired
    private BusiFileService busiFileService;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;
    @Autowired
    private EduTalentService eduTalentService;
    @Autowired
    private EduPrivateAppointStudentService eduPrivateAppointStudentService;

    @Autowired
    private OperationCacheIntegration operationCacheIntegration;
    @Autowired
    private EduHouseIntegration eduHouseIntegration;
    @Autowired
    private EduSocialSecurityIntegration eduSocialSecurityIntegration;
    @Autowired
    private EduLivePlaceIntegration eduLivePlaceIntegration;
    @Autowired
    private EduNetsignIntegration eduNetsignIntegration;
    @Autowired
    private EduStudentEnrollWhiteService eduStudentEnrollWhiteService;
    @Value("${spring.servlet.multipart.location}")
    private String tempPath;

    @Autowired
    private  EduDataTaskDetailService eduDataTaskDetailService;

    @Autowired
    public EduhStudentEnrollPreService eduhStudentEnrollPreService;

    @Autowired
    private static final String STUDENT_ENROLL_PRE = "edu_student_enroll_pre";


    @Override
    @OpApi(funcCode = "edustudentenrollpre0001", title = "预采集管理分页查询（PC）", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollPreVO> getList(EduStudentEnrollPreQueryVO vo) {
        Boolean desensitizeFlag = vo.getDesensitizeFlag();
        if (desensitizeFlag == null){
            desensitizeFlag = true;
        }

        if (AuthStatusEnum.YES.getType().equalsIgnoreCase(vo.getAuthStatus())) {
            // 开启分页
            if (vo.getPageNum() == null || vo.getPageSize() == null) {
                //如果不传入分页参数，默认最大取1000条
                vo.setPageNum(1);
                vo.setPageSize(1000);
            }

            // 判断是否查询历史表
            Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), STUDENT_ENROLL_PRE));
            QueryWrapper<?> enrollPreQueryWrapper;
            List<?> list;
            if (!queryHistoryFlag) {
                // 没有迁移查询
                enrollPreQueryWrapper = createQueryWrapper(vo);
            } else {
                // 迁移过后，判断是否加密
                Boolean encryptFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyHistoryEncrypt(vo.getYear(), STUDENT_ENROLL_PRE));
                if (encryptFlag) {
                    //加密查询条件
                    if (StringUtils.isNotBlank(vo.getIdcard())){
                        vo.setIdcard(CommonSecureUtil.sm4Encrypt(vo.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(vo.getFullName())){
                        vo.setFullName(CommonSecureUtil.sm4Encrypt(vo.getFullName()));
                    }
                    if (StringUtils.isNotBlank(vo.getFatherName())){
                        vo.setFatherName(CommonSecureUtil.sm4Encrypt(vo.getFatherName()));
                    }
                    if (StringUtils.isNotBlank(vo.getFatherIdcard())){
                        vo.setFatherIdcard(CommonSecureUtil.sm4Encrypt(vo.getFatherIdcard()));
                    }
                    if (StringUtils.isNotBlank(vo.getFatherCellphone())){
                        vo.setFatherCellphone(CommonSecureUtil.sm4Encrypt(vo.getFatherCellphone()));
                    }
                    if (StringUtils.isNotBlank(vo.getMotherName())){
                        vo.setMotherName(CommonSecureUtil.sm4Encrypt(vo.getMotherName()));
                    }
                    if (StringUtils.isNotBlank(vo.getMotherIdcard())){
                        vo.setMotherIdcard(CommonSecureUtil.sm4Encrypt(vo.getMotherIdcard()));
                    }
                    if (StringUtils.isNotBlank(vo.getMotherCellphone())){
                        vo.setMotherCellphone(CommonSecureUtil.sm4Encrypt(vo.getMotherCellphone()));
                    }
                }
                enrollPreQueryWrapper = createQueryWrapperHistory(vo);
            }

            // 分页查询
            PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            if (!queryHistoryFlag) {
                list = eduStudentEnrollPreService.list((QueryWrapper<EduStudentEnrollPre>) enrollPreQueryWrapper);
            } else {
                list = eduhStudentEnrollPreService.list((QueryWrapper<EduhStudentEnrollPre>) enrollPreQueryWrapper);
            }

            // 判断查询结果是否为空
            if (CollectionUtils.isEmpty(list)) {
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }

            // 不为空则获取分页结果
            PageInfo<?> pageInfo = new PageInfo<>(list);
            List<EduStudentEnrollPreVO> resultList = Convert.toList(EduStudentEnrollPreVO.class, pageInfo.getList());
            List<String> empIdList = resultList.stream().map(EduStudentEnrollPreVO::getStudentEnrollPreId).distinct().collect(Collectors.toList());
            QueryWrapper<EduStudentEnrollFamily> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().in(EduStudentEnrollFamily::getStudentEnrollPreId, empIdList);
            List<EduStudentEnrollFamily> familyList = eduStudentEnrollFamilyService.list(queryWrapper);
            Map<String, List<EduStudentEnrollFamily>> groupBy = new HashMap<>();
            if (!CollectionUtils.isEmpty(familyList)) {
                groupBy = familyList.stream().collect(Collectors.groupingBy(EduStudentEnrollFamily::getStudentEnrollPreId));
            }
            for (EduStudentEnrollPreVO enrollPre : resultList) {
                if ("1".equals(enrollPre.getEncryptFlag())){
                    if (StringUtils.isNotBlank(enrollPre.getIdcard())){
                        enrollPre.setIdcard(CommonSecureUtil.sm4Decrypt(enrollPre.getIdcard()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getFullName())){
                        enrollPre.setFullName(CommonSecureUtil.sm4Decrypt(enrollPre.getFullName()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getFatherName())){
                        enrollPre.setFatherName(CommonSecureUtil.sm4Decrypt(enrollPre.getFatherName()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getFatherIdcard())){
                        enrollPre.setFatherIdcard(CommonSecureUtil.sm4Decrypt(enrollPre.getFatherIdcard()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getFatherCellphone())){
                        enrollPre.setFatherCellphone(CommonSecureUtil.sm4Decrypt(enrollPre.getFatherCellphone()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getMotherName())){
                        enrollPre.setMotherName(CommonSecureUtil.sm4Decrypt(enrollPre.getMotherName()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getMotherIdcard())){
                        enrollPre.setMotherIdcard(CommonSecureUtil.sm4Decrypt(enrollPre.getMotherIdcard()));
                    }
                    if (StringUtils.isNotBlank(enrollPre.getMotherCellphone())){
                        enrollPre.setMotherCellphone(CommonSecureUtil.sm4Decrypt(enrollPre.getMotherCellphone()));
                    }
                }
                String schoolId = enrollPre.getSchoolId();
                //学校信息查询
                if (StringUtils.isNotBlank(schoolId)) {
                    EduSchoolVO school = eduSchoolService.getDetail(schoolId);
                    if (school != null) {
                        enrollPre.setSchoolName(school.getSchoolName());
                        enrollPre.setSchoolNature(school.getSchoolNature());
                        enrollPre.setShortName(school.getShortName());
                        if (StringUtils.isBlank(enrollPre.getSchoolCategory())) {
                            enrollPre.setSchoolCategory(school.getSchoolCategory());
                        }
                    }
                }
                if (StringUtils.isNotBlank(vo.getOrgId())) {
                    EduSchoolVO school = eduSchoolService.getDetail(vo.getOrgId());
                    if (school != null) {
                        enrollPre.setCjSchoolName(school.getSchoolName());
                    }
                }
                //设置监护人信息
                this.searchGuardians(enrollPre, groupBy.get(enrollPre.getStudentEnrollPreId()));
                //脱敏
                if (desensitizeFlag) {
                    enrollPre.setIdcard(EduDesensitizeUtil.desensitizeIdcard(enrollPre.getIdcard()));
                    enrollPre.setFullName(EduDesensitizeUtil.desensitizeFullName(enrollPre.getFullName()));
                    enrollPre.setCellphone(EduDesensitizeUtil.desensitizeCellphone(enrollPre.getCellphone()));
                    enrollPre.setFatherName(EduDesensitizeUtil.desensitizeFullName(enrollPre.getFatherName()));
                    enrollPre.setFatherIdcard(EduDesensitizeUtil.desensitizeIdcard(enrollPre.getFatherIdcard()));
                    enrollPre.setFatherCellphone(EduDesensitizeUtil.desensitizeCellphone(enrollPre.getFatherCellphone()));
                    enrollPre.setMotherName(EduDesensitizeUtil.desensitizeFullName(enrollPre.getMotherName()));
                    enrollPre.setMotherIdcard(EduDesensitizeUtil.desensitizeIdcard(enrollPre.getMotherIdcard()));
                    enrollPre.setMotherCellphone(EduDesensitizeUtil.desensitizeCellphone(enrollPre.getMotherCellphone()));
                }
            }

            // 转义数据字典值
            dictHelper.valueToName(resultList, Arrays.asList(EduEnrollPreDictEnum.values()));
            return PagerUtil.parsePagerVo(resultList, pageInfo);
        } else {
            QueryWrapper<EduBusiEnrollPre> enrollPreQueryWrapper = createBusiQueryWrapper(vo);
            // 开启分页
            if (vo.getPageNum() != null && vo.getPageSize() != null) {
                PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
            }
            List<EduBusiEnrollPre> list = eduBusiEnrollPreService.list(enrollPreQueryWrapper);
            if (CollectionUtils.isEmpty(list)) {
                // 判断是否为空，为空则返回空参数
                return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
            }
            // 不为空则获取分页结果
            PageInfo<EduBusiEnrollPre> pageInfo = new PageInfo<>(list);
            // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
            List<EduStudentEnrollPreVO> resultList =
                    Convert.toList(EduStudentEnrollPreVO.class, pageInfo.getList());
            List<String> empIdList = resultList.stream().map(EduStudentEnrollPreVO::getStudentEnrollPreId).distinct().collect(Collectors.toList());
            QueryWrapper<EduStudentEnrollFamily> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().in(EduStudentEnrollFamily::getStudentEnrollPreId, empIdList);
            List<EduStudentEnrollFamily> familyList = eduStudentEnrollFamilyService.list(queryWrapper);
            Map<String, List<EduStudentEnrollFamily>> groupBy = new HashMap<>();
            if (!CollectionUtils.isEmpty(familyList)) {
                groupBy = familyList.stream().collect(Collectors.groupingBy(EduStudentEnrollFamily::getStudentEnrollPreId));
            }
            for (EduStudentEnrollPreVO enrollPre : resultList) {
                String schoolId = enrollPre.getSchoolId();
                //学校信息查询
                if (StringUtils.isNotBlank(schoolId)) {
                    EduSchoolVO school = eduSchoolService.getDetail(schoolId);
                    if (school != null) {
                        enrollPre.setSchool(school.getSchoolName());
                        enrollPre.setSchoolNature(school.getSchoolNature());
                        enrollPre.setShortName(school.getShortName());
                        if (StringUtils.isBlank(vo.getSchoolCategory())) {
                            enrollPre.setSchoolCategory(school.getSchoolCategory());
                        }
                    }
                }
                if (StringUtils.isNotBlank(enrollPre.getOrgId())) {
                    EduSchoolVO school = eduSchoolService.getDetail(enrollPre.getOrgId());
                    if (school != null) {
                        enrollPre.setCjSchoolName(school.getSchoolName());
                    }
                }
                //设置监护人信息
                this.searchGuardians(enrollPre, groupBy.get(enrollPre.getStudentEnrollPreId()));

                //脱敏
                if (desensitizeFlag) {
                    enrollPre.setIdcard(EduDesensitizeUtil.desensitizeIdcard(enrollPre.getIdcard()));
                    enrollPre.setFullName(EduDesensitizeUtil.desensitizeFullName(enrollPre.getFullName()));
                    enrollPre.setCellphone(EduDesensitizeUtil.desensitizeCellphone(enrollPre.getCellphone()));
                    enrollPre.setFatherName(EduDesensitizeUtil.desensitizeFullName(enrollPre.getFatherName()));
                    enrollPre.setFatherIdcard(EduDesensitizeUtil.desensitizeIdcard(enrollPre.getFatherIdcard()));
                    enrollPre.setFatherCellphone(EduDesensitizeUtil.desensitizeCellphone(enrollPre.getFatherCellphone()));
                    enrollPre.setMotherName(EduDesensitizeUtil.desensitizeFullName(enrollPre.getMotherName()));
                    enrollPre.setMotherIdcard(EduDesensitizeUtil.desensitizeIdcard(enrollPre.getMotherIdcard()));
                    enrollPre.setMotherCellphone(EduDesensitizeUtil.desensitizeCellphone(enrollPre.getMotherCellphone()));
                }
            }
            // 转义数据字典值
            dictHelper.valueToName(resultList, Arrays.asList(EduEnrollPreDictEnum.values()));
            return PagerUtil.parsePagerVo(resultList, pageInfo);
        }
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0002", title = "预采集管理表根据主键查询详情", funcType = FuncTypeEnum.query)
    public EduStudentEnrollPreVO getById(EduStudentEnrollPreKeyVO vo) {
//        Long busNo;
        String schoolId;
        if (vo.getYear() == null){
            vo.setYear(eduHelper.thisYear());
        }

        EduStudentEnrollPreVO eduStudentEnrollPreVO = new EduStudentEnrollPreVO();
        if (StringUtils.isNotBlank(vo.getStudentEnrollPreId())) {
            String studentEnrollPreId = vo.getStudentEnrollPreId();
            //判断是否迁移过
            EduStudentEnrollPre enrollPre;
            Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), STUDENT_ENROLL_PRE));
            if (!queryHistoryFlag) {
                enrollPre = eduStudentEnrollPreService.getById(studentEnrollPreId);
                if (enrollPre == null) {
                    throw new AppException("未找到详细信息");
                }
            }else{
                EduhStudentEnrollPre eduhStudentEnrollPre = eduhStudentEnrollPreService.getById(studentEnrollPreId);
                if (eduhStudentEnrollPre == null) {
                    throw new AppException("未找到详细信息");
                }
                //解密
                if ("1".equals(eduhStudentEnrollPre.getEncryptFlag())){
                    eduStudentEnrollPreService.decrypt(eduhStudentEnrollPre);
                }
                enrollPre = Convert.convert(EduStudentEnrollPre.class, eduhStudentEnrollPre);
            }

            BeanUtil.copyProperties(enrollPre, eduStudentEnrollPreVO, CopyOptions.create().ignoreNullValue());
            //查询监护人信息
            this.searchGuardians(eduStudentEnrollPreVO);
            schoolId = enrollPre.getSchoolId();

            //审核是标红修改过的字段
            QueryWrapper<EduBusiEnrollPre> busiEnrollPreQueryWrapper = new QueryWrapper<>();
            busiEnrollPreQueryWrapper.lambda().eq(EduBusiEnrollPre::getStudentEnrollPreId, enrollPre.getStudentEnrollPreId())
            .eq(EduBusiEnrollPre::getAuthStatus,AuthStatusEnum.NODO.getType()).orderByDesc(EduBusiEnrollPre::getCreateTime);
            List<EduBusiEnrollPre> eduBusiEnrollPreList = eduBusiEnrollPreService.list(busiEnrollPreQueryWrapper);
            if (!CollectionUtils.isEmpty(eduBusiEnrollPreList)) {
                EduBusiEnrollPre eduBusiEnrollPre = new EduBusiEnrollPre();
                eduBusiEnrollPre = eduBusiEnrollPreList.get(0);
                EduStudentEnrollPreVO oldeduStudentEnrollPreVO = new EduStudentEnrollPreVO();
                BeanUtil.copyProperties(eduBusiEnrollPre, oldeduStudentEnrollPreVO, CopyOptions.create().ignoreNullValue());

                List<ModifiedFieldVO> changList =
                        FieldChangeUtil.getModifyContentRemove(
                                oldeduStudentEnrollPreVO, eduStudentEnrollPreVO, RemoveField.getBaseRemove());

                eduStudentEnrollPreVO.setChangeFieldList(changList);
            }


            //

        } else if (vo.getBusiEnrollPreId() != null) {
            Long enrollPreId = vo.getBusiEnrollPreId();
            EduBusiEnrollPre enrollPre = eduBusiEnrollPreService.getById(enrollPreId);
            if (enrollPre == null) {
                throw new AppException("未找到详细信息");
            }
            BeanUtil.copyProperties(enrollPre, eduStudentEnrollPreVO, CopyOptions.create().ignoreNullValue());
            //查询监护人信息
            this.searchGuardians(eduStudentEnrollPreVO);
            schoolId = enrollPre.getSchoolId();
        } else {
            throw new AppException("查询的主键不能为空");
        }

        // 查询学校信息
        if (StringUtils.isNotBlank(schoolId)) {
            EduSchoolVO school = eduSchoolService.getDetail(schoolId);
            if (school != null) {
                String oldorgid = eduStudentEnrollPreVO.getOrgId();

                BeanUtil.copyProperties(school, eduStudentEnrollPreVO, CopyOptions.create().ignoreNullValue());
                //BeanUtil.copyProperties(school, enrollPre, CopyOptions.create().ignoreNullValue());
                eduStudentEnrollPreVO.setOrgId(oldorgid);
            }

        }
        if (StringUtils.isNotBlank(eduStudentEnrollPreVO.getOrgId())) {
            EduSchoolVO school = eduSchoolService.getDetail(eduStudentEnrollPreVO.getOrgId());
            if (school != null) {
                eduStudentEnrollPreVO.setCjSchoolName(school.getSchoolName());
            }
        }
        if (StringUtils.isBlank(eduStudentEnrollPreVO.getFatherCardType())) {
            eduStudentEnrollPreVO.setFatherCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(eduStudentEnrollPreVO.getMotherCardType())) {
            eduStudentEnrollPreVO.setMotherCardType(CardTypeEnum.idcard.getType());
        }
        dictHelper.valueToName(eduStudentEnrollPreVO, Arrays.asList(EduEnrollPreDictEnum.values()));

        return eduStudentEnrollPreVO;
    }

    /**
     * 查询监护人信息
     *
     * @param enrollPre
     * @return
     */
    private void searchGuardians(EduStudentEnrollPreVO enrollPre) {
        String studentEnrollPreId = enrollPre.getStudentEnrollPreId();
        if (StringUtils.isNotBlank(studentEnrollPreId)) {
            QueryWrapper<EduStudentEnrollFamily> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduStudentEnrollFamily::getStudentEnrollPreId, studentEnrollPreId);
            List<EduStudentEnrollFamily> familyList = eduStudentEnrollFamilyService.list(queryWrapper);
            if (CollectionUtils.isEmpty(familyList)) {
                List<EduStudentEnrollFamilyVO> guardians = new ArrayList<>();
                EduStudentEnrollFamilyVO familyVOFather = new EduStudentEnrollFamilyVO();
                EduStudentEnrollFamilyVO familyVOMother = new EduStudentEnrollFamilyVO();
                if (!StringUtils.isBlank(enrollPre.getFatherIdcard())) {
                    familyVOFather.setIdcard(enrollPre.getFatherIdcard());
                    familyVOFather.setFullName(enrollPre.getFatherName());
                    familyVOFather.setCardType(enrollPre.getFatherCardType());
                    familyVOFather.setWork(enrollPre.getFatherWork());
                    familyVOFather.setCellphone(enrollPre.getFatherCellphone());
                    familyVOFather.setRelationshipType("1");
                }
                if (!StringUtils.isBlank(enrollPre.getMotherIdcard())) {
                    familyVOMother.setIdcard(enrollPre.getMotherIdcard());
                    familyVOMother.setFullName(enrollPre.getMotherName());
                    familyVOMother.setRelationshipType("2");
                    familyVOMother.setCardType(enrollPre.getMotherCardType());
                    familyVOMother.setWork(enrollPre.getMotherWork());
                    familyVOMother.setCellphone(enrollPre.getMotherCellphone());
                }
                guardians.add(familyVOFather);
                guardians.add(familyVOMother);
                enrollPre.setFamilyList(guardians);
            } else {
                searchGuardians(enrollPre, familyList);
            }
        }
    }

    private void searchGuardians(EduStudentEnrollPreVO enrollPre, List<EduStudentEnrollFamily> familyList) {
        List<EduStudentEnrollFamilyVO> guardians = new ArrayList<>();
        if (!CollectionUtils.isEmpty(familyList)) {
            for (EduStudentEnrollFamily enrollFamily : familyList) {
                EduStudentEnrollFamilyVO familyVO = Convert.convert(EduStudentEnrollFamilyVO.class, enrollFamily);
                guardians.add(familyVO);
                if (RelationTypeEnum.father.getType().equals(enrollFamily.getRelationshipType())) {
                    enrollPre.setFatherIdcard(enrollFamily.getIdcard());
                    enrollPre.setFatherName(enrollFamily.getFullName());
                    enrollPre.setFatherCardType(enrollFamily.getCardType());
                    enrollPre.setFatherWork(enrollFamily.getWork());
                    enrollPre.setFatherCellphone(enrollFamily.getCellphone());
                } else if (RelationTypeEnum.mother.getType().equals(enrollFamily.getRelationshipType())) {
                    enrollPre.setMotherIdcard(enrollFamily.getIdcard());
                    enrollPre.setMotherName(enrollFamily.getFullName());
                    enrollPre.setMotherCardType(enrollFamily.getCardType());
                    enrollPre.setMotherWork(enrollFamily.getWork());
                    enrollPre.setMotherCellphone(enrollFamily.getCellphone());
                } else {
                    if (BoolEnum.TRUE.getType().equalsIgnoreCase(enrollFamily.getHouseFlag())) {
                        enrollPre.setRelationshipType(enrollFamily.getRelationshipType());
                        enrollPre.setRelationshipName(enrollFamily.getFullName());
                        enrollPre.setRelationshipIdcard(enrollFamily.getIdcard());
                        enrollPre.setRelationshipCardType(enrollFamily.getCardType());
                        enrollPre.setWork(enrollFamily.getWork());
                        enrollPre.setCellphone(enrollFamily.getCellphone());
                    }

                }
            }
        }
        enrollPre.setFamilyList(guardians);
    }

    /**
     * 保存前统一校验
     */
    @Override
    @OpApi(funcCode = "edustudentenrollpre0003", title = "预采集管理保存前校验", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void checkSave(EduStudentEnrollPreVO vo) {
        if (vo.getManagerFlag()) {
            List<EduStudentEnrollFamilyVO> familyList = vo.getFamilyList();
            boolean flag = false;
            if (!CollectionUtils.isEmpty(familyList)) {
                Map<String, Integer> cfMap = new HashMap<>();
                for (EduStudentEnrollFamilyVO eduStudentEnrollFamilyVO : familyList) {

                    if (cfMap.get(eduStudentEnrollFamilyVO.getRelationshipType()) == null) {
                        cfMap.put(eduStudentEnrollFamilyVO.getRelationshipType(), 1);
                    } else {
                        throw new AppException("监护人" + RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()) != null ? RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()).getName() : "" + "重复");
                    }
                    if (RelationTypeEnum.father.getType().equals(eduStudentEnrollFamilyVO.getRelationshipType())) {
                        if (StringUtils.isBlank(eduStudentEnrollFamilyVO.getCardType())) {
                            eduStudentEnrollFamilyVO.setCardType(CardTypeEnum.idcard.getType());
                        }

                        vo.setFatherName(eduStudentEnrollFamilyVO.getFullName());
                        vo.setFatherCardType(eduStudentEnrollFamilyVO.getCardType());
                        vo.setFatherIdcard(eduStudentEnrollFamilyVO.getIdcard());
                        vo.setFatherWork(eduStudentEnrollFamilyVO.getWork());
                        vo.setFatherCellphone(eduStudentEnrollFamilyVO.getCellphone());

                        if (CardTypeEnum.idcard.getType().equals(vo.getFatherCardType()) && !IdcardUtil.isValidCard(vo.getFatherIdcard())) {
                            throw new AppException("父亲身份证有误！");
                        }
                        if (ObjectUtils.isEmpty(vo.getFatherName()) || ObjectUtils.isEmpty(vo.getFatherName().trim())) {
                            throw new AppException("父亲姓名不能为空！");
                        } else {
                            vo.setFatherName(
                                    Validator.isChinese(vo.getFatherName())
                                            ? vo.getFatherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                            : vo.getFatherName().trim());
                        }
                        if (!ObjectUtils.isEmpty(vo.getFatherCellphone()) && !PhoneUtil.isMobile(vo.getFatherCellphone())) {
                            throw new AppException("请输入正确的父亲手机号码！");
                        }
                        flag = true;
                    } else if (RelationTypeEnum.mother.getType().equals(eduStudentEnrollFamilyVO.getRelationshipType())) {
                        if (StringUtils.isBlank(eduStudentEnrollFamilyVO.getCardType())) {
                            eduStudentEnrollFamilyVO.setCardType(CardTypeEnum.idcard.getType());
                        }
                        vo.setMotherName(eduStudentEnrollFamilyVO.getFullName());
                        vo.setMotherCardType(eduStudentEnrollFamilyVO.getCardType());
                        vo.setMotherIdcard(eduStudentEnrollFamilyVO.getIdcard());
                        vo.setMotherWork(eduStudentEnrollFamilyVO.getWork());
                        vo.setMotherCellphone(eduStudentEnrollFamilyVO.getCellphone());
                        if (CardTypeEnum.idcard.getType().equals(vo.getMotherCardType()) && !IdcardUtil.isValidCard(vo.getMotherIdcard())) {
                            throw new AppException("母亲身份证有误！");
                        }
                        if (ObjectUtils.isEmpty(vo.getMotherName()) || ObjectUtils.isEmpty(vo.getMotherName().trim())) {
                            throw new AppException("母亲姓名不能为空！");
                        } else {
                            vo.setMotherName(
                                    Validator.isChinese(vo.getMotherName())
                                            ? vo.getMotherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                            : vo.getMotherName().trim());
                        }
                        if (!ObjectUtils.isEmpty(vo.getMotherCellphone()) && !PhoneUtil.isMobile(vo.getMotherCellphone())) {
                            throw new AppException("请输入正确的母亲手机号码！");
                        }
                        flag = true;
                    } else {
                        if (StringUtils.isBlank(eduStudentEnrollFamilyVO.getCardType())) {
                            eduStudentEnrollFamilyVO.setCardType(CardTypeEnum.idcard.getType());
                        }
                        vo.setRelationshipName(eduStudentEnrollFamilyVO.getFullName());
                        vo.setRelationshipCardType(eduStudentEnrollFamilyVO.getCardType());
                        vo.setWork(eduStudentEnrollFamilyVO.getWork());
                        vo.setCellphone(eduStudentEnrollFamilyVO.getCellphone());
                        vo.setRelationshipType(eduStudentEnrollFamilyVO.getRelationshipType());
                        vo.setRelationshipIdcard(eduStudentEnrollFamilyVO.getIdcard().trim().toUpperCase());
                        String reType = RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()) != null ? RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()).getName() : "";
                        if (CardTypeEnum.idcard.getType().equals(vo.getRelationshipCardType()) && !IdcardUtil.isValidCard(vo.getRelationshipIdcard())) {
                            throw new AppException("监护人" + reType + "身份证有误！");
                        }
                        if (ObjectUtils.isEmpty(vo.getRelationshipName()) || ObjectUtils.isEmpty(vo.getRelationshipName().trim())) {
                            throw new AppException("监护人" + reType + "姓名不能为空！");
                        } else {
                            vo.setRelationshipName(
                                    Validator.isChinese(vo.getRelationshipName())
                                            ? vo.getRelationshipName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                            : vo.getRelationshipName().trim());
                        }
                        if (!ObjectUtils.isEmpty(vo.getCellphone()) && !PhoneUtil.isMobile(vo.getCellphone())) {
                            throw new AppException("请输入正确的监护人" + reType + "手机号码！");
                        }

                    }
                }
                if (!flag) {
                    vo.setFatherName(vo.getRelationshipName());
                    vo.setFatherCardType(vo.getRelationshipCardType());
                    vo.setFatherIdcard(vo.getRelationshipIdcard());
                    vo.setFatherWork(vo.getWork());
                    vo.setFatherCellphone(vo.getCellphone());
                }
            }

        }
        //字段校验
        checkBase(vo);

        String userId = SessionUtil.getUserId();
        String fullName = SessionUtil.getFullName();
        String cellphone = SessionUtil.getSessionInfo().getCellphone();
        if (ObjectUtils.isEmpty(vo.getStudentEnrollPreId())) {
            vo.setType(SaveTypeEnum.INSERT.getType());
            if (EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                //准新生登记
                LambdaQueryWrapper<EduBusiEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(EduBusiEnrollPre::getIdcard, vo.getIdcard()).eq(EduBusiEnrollPre::getYear, vo.getYear())
                        .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NODO.getType());
                ;
                if (eduBusiEnrollPreService.count(queryWrapper) > 0) {
                    throw new AppException("该学生信息已登记，处于待审核状态，请耐心等待工作人员审核");
                }
            }
            //新增校验
            //判断学生信息是否存在
            LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(EduStudentEnrollPre::getIdcard, vo.getIdcard()).eq(EduStudentEnrollPre::getYear, vo.getYear());
            if (eduStudentEnrollPreService.count(queryWrapper) > 0) {
                throw new AppException("该学生信息已存在,不能重复登记");
            }
            vo.setBeforeFlag("0");
            vo.setCalculateFlag("0");
            vo.setHouseholdSyncFlag("0");
            vo.setHouseSyncFlag("0");
            vo.setNetsignSyncFlag("0");
            vo.setCbSyncFlag("0");
            vo.setQySyncFlag("0");
            vo.setFamilyFlag("0");
            vo.setConsistentFlag("0");
            if(StringUtils.isBlank(vo.getConsistentType())){
                vo.setConsistentType("1");
            }
        } else {
            //判断学生信息是否存在
            LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(EduStudentEnrollPre::getIdcard, vo.getIdcard())
                    .ne(EduStudentEnrollPre::getStudentEnrollPreId, vo.getStudentEnrollPreId())
                    .eq(EduStudentEnrollPre::getYear, vo.getYear());
            if (eduStudentEnrollPreService.count(queryWrapper) > 0) {
                throw new AppException("该学生信息已存在,不能修改");
            }
            vo.setType(SaveTypeEnum.UPDATE.getType());
        }
        if (!vo.getManagerFlag() && EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            //家长端登记审核不通过修改次数控制
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("lock_edit_student_pre");
            int max = 3;
            String maxValue = commonIntegration.getValueByKey(commonVO);
            if (StringUtils.isNotBlank(maxValue)) {
                try {
                    max = Integer.valueOf(maxValue);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            QueryWrapper<EduBusiEnrollPre> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduBusiEnrollPre::getYear, vo.getYear())
                    .eq(EduBusiEnrollPre::getIdcard, vo.getIdcard())
                    .eq(StringUtils.isNotBlank(vo.getAreaCode()), EduBusiEnrollPre::getAreaCode, vo.getAreaCode())
                    .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NO.getType());
            if (eduBusiEnrollPreService.count(queryWrapper) >= max) {
                throw new AppException("因您频繁进行信息登记与修改，系统拒绝您再次提起登记与修改。申请解锁请联系教育局相关工作人员！");
            }
            vo.setSubmitterId(userId);
            vo.setSubmitterName(fullName);
            vo.setTelphone(cellphone);
        }

    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0004", title = "预采集管理excel导入保存（PC）", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "edustudentenrollpre0004",
            operationName = "预采集管理excel导入保存（PC）",
            dataType = "batch",
            auType = AuTypeEnum.OTHER)
    public void addExcel(EduStudentEnrollExcelSaveVO vo) {
        if (CollectionUtils.isEmpty(vo.getEduStudentEnrollPreVOList())) {
            throw new AppException("没有传入需要保存的信息");
        }
        String orgId = SessionUtil.getOrgId();
        String enrollPreType = EnrollPreTypeEnum.ycj.getType();
        String areaCode = "";
        String areaName = "";
        String userId = SessionUtil.getUserId();
        String fullName = SessionUtil.getFullName();
        String cellphone = "";
        if (SessionUtil.getSessionInfo() != null) {
            areaCode = SessionUtil.getAreaCode();
            areaName = SessionUtil.getSessionInfo().getAreaName();
            cellphone = SessionUtil.getSessionInfo().getCellphone();
        }
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setAreaCode(areaCode);
        queryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        //判断是否在经办业务期内
        eduSystemConfigIntegration.checkOperation(eduOperationCacheVO, "YW027");
        Integer year = eduOperationCacheVO.getYear();
        Long batchNo =
                Long.parseLong(
                        System.currentTimeMillis() + RandomUtil.randomNumbers(6));
        for (EduStudentEnrollPreVO saveVO : vo.getEduStudentEnrollPreVOList()) {
            if (StringUtils.isBlank(saveVO.getAreaCode())) {
                saveVO.setAreaCode(areaCode);
                saveVO.setAreaName(areaName);
            }
            if (saveVO.getYear() == null) {
                saveVO.setYear(year);
            }
            saveVO.setEnrollPreType(enrollPreType);
            saveVO.setBatchNo(batchNo);
            saveVO.setAuthUserId(userId);
            saveVO.setSubmitterId(userId);
            saveVO.setSubmitterName(fullName);
            saveVO.setAuthTime(new Date());
            saveVO.setTelphone(cellphone);
            saveVO.setOrgId(orgId);
            eduStudentEnrollPreService.saveSuccessExcel(saveVO);
        }
    }


    private void saveFamily(EduStudentEnrollPreVO saveVO, boolean uploadFlag) {
        if (uploadFlag) {
            eduStudentEnrollFamilyService.delByPreId(saveVO.getStudentEnrollPreId());
        }
        List<EduStudentEnrollFamily> familyList = new ArrayList<>();//新增
        if (!CollectionUtils.isEmpty(saveVO.getFamilyList())) {
            for (EduStudentEnrollFamilyVO eduStudentEnrollFamilyVO : saveVO.getFamilyList()) {
                if (RelationTypeEnum.mother.getType().equals(eduStudentEnrollFamilyVO.getRelationshipType())) {
                    PersonInfo moPersonInfo =
                            this.savePerson(saveVO.getMotherIdcard().toUpperCase(), saveVO.getMotherCardType(), saveVO.getMotherName());
                    saveVO.setMotherId(moPersonInfo.getPersonId());
                    saveVO.setMotherIdcard(saveVO.getMotherIdcard().toUpperCase());

                    EduStudentEnrollFamily family = new EduStudentEnrollFamily();
                    family.setStudentEnrollPreId(saveVO.getStudentEnrollPreId());
                    family.setCardType(eduStudentEnrollFamilyVO.getCardType());
                    family.setIdcard(eduStudentEnrollFamilyVO.getIdcard());
                    family.setPersonId(saveVO.getMotherId());
                    family.setFullName(eduStudentEnrollFamilyVO.getFullName());
                    family.setRelationshipType(RelationTypeEnum.mother.getType());
                    family.setHouseFlag(BoolEnum.TRUE.getType());
                    family.setCellphone(eduStudentEnrollFamilyVO.getCellphone());
                    family.setWork(eduStudentEnrollFamilyVO.getWork());
                    family.setFamilyFlag("0");
                    familyList.add(family);
                } else if (RelationTypeEnum.father.getType().equals(eduStudentEnrollFamilyVO.getRelationshipType())) {
                    PersonInfo faPersonInfo =
                            this.savePerson(saveVO.getFatherIdcard().toUpperCase(), saveVO.getFatherCardType(), saveVO.getFatherName());
                    saveVO.setFatherId(faPersonInfo.getPersonId());
                    saveVO.setFatherIdcard(saveVO.getFatherIdcard().toUpperCase());
                    EduStudentEnrollFamily family = new EduStudentEnrollFamily();
                    family.setStudentEnrollPreId(saveVO.getStudentEnrollPreId());
                    family.setCardType(eduStudentEnrollFamilyVO.getCardType());
                    family.setIdcard(eduStudentEnrollFamilyVO.getIdcard());
                    family.setPersonId(saveVO.getFatherId());
                    family.setFullName(eduStudentEnrollFamilyVO.getFullName());
                    family.setRelationshipType(RelationTypeEnum.father.getType());
                    family.setHouseFlag(BoolEnum.TRUE.getType());
                    family.setCellphone(eduStudentEnrollFamilyVO.getCellphone());
                    family.setWork(eduStudentEnrollFamilyVO.getWork());
                    family.setFamilyFlag("0");
                    familyList.add(family);
                } else {
                    PersonInfo personInfo =
                            this.savePerson(saveVO.getRelationshipIdcard().toUpperCase(), saveVO.getRelationshipCardType(), saveVO.getRelationshipName());
                    saveVO.setRelationshipIdcard(saveVO.getRelationshipIdcard().toUpperCase());
                    EduStudentEnrollFamily family = new EduStudentEnrollFamily();
                    family.setStudentEnrollPreId(saveVO.getStudentEnrollPreId());
                    family.setCardType(eduStudentEnrollFamilyVO.getCardType());
                    family.setIdcard(eduStudentEnrollFamilyVO.getIdcard());
                    family.setPersonId(personInfo.getPersonId());
                    family.setFullName(eduStudentEnrollFamilyVO.getFullName());
                    family.setRelationshipType(eduStudentEnrollFamilyVO.getRelationshipType());
                    family.setHouseFlag(BoolEnum.TRUE.getType());
                    family.setCellphone(eduStudentEnrollFamilyVO.getCellphone());
                    family.setWork(eduStudentEnrollFamilyVO.getWork());
                    family.setFamilyFlag("0");
                    familyList.add(family);
                }
            }
        } else {
            //管理端取消 监护人信息栏 ，合并到基本信息里，所以familyList 为空了
            //else if(EnrollPreTypeEnum.dj.getType().equals(saveVO.getEnrollPreType())||EnrollPreTypeEnum.ycj.getType().equals(saveVO.getEnrollPreType())){
            if (StringUtils.isNotBlank(saveVO.getMotherIdcard())) {
                PersonInfo moPersonInfo =
                        this.savePerson(saveVO.getMotherIdcard().toUpperCase(), saveVO.getMotherCardType(), saveVO.getMotherName());
                saveVO.setMotherId(moPersonInfo.getPersonId());
                saveVO.setMotherIdcard(saveVO.getMotherIdcard().toUpperCase());
                EduStudentEnrollFamily family = new EduStudentEnrollFamily();
                family.setStudentEnrollPreId(saveVO.getStudentEnrollPreId());
                family.setCardType(saveVO.getMotherCardType());
                family.setIdcard(saveVO.getMotherIdcard());
                family.setPersonId(saveVO.getMotherId());
                family.setFullName(saveVO.getMotherName());
                family.setRelationshipType(RelationTypeEnum.mother.getType());
                family.setHouseFlag(BoolEnum.TRUE.getType());
                family.setCellphone(saveVO.getMotherCellphone());
                family.setWork(saveVO.getMotherWork());
                family.setFamilyFlag("0");
                familyList.add(family);
            }
            if (StringUtils.isNotBlank(saveVO.getFatherIdcard())) {
                PersonInfo faPersonInfo =
                        this.savePerson(saveVO.getFatherIdcard().toUpperCase(), saveVO.getFatherCardType(), saveVO.getFatherName());
                saveVO.setFatherId(faPersonInfo.getPersonId());
                saveVO.setFatherIdcard(saveVO.getFatherIdcard().toUpperCase());
                EduStudentEnrollFamily family = new EduStudentEnrollFamily();
                family.setStudentEnrollPreId(saveVO.getStudentEnrollPreId());
                family.setCardType(saveVO.getFatherCardType());
                family.setIdcard(saveVO.getFatherIdcard());
                family.setPersonId(saveVO.getFatherId());
                family.setFullName(saveVO.getFatherName());
                family.setRelationshipType(RelationTypeEnum.father.getType());
                family.setHouseFlag(BoolEnum.TRUE.getType());
                family.setCellphone(saveVO.getFatherCellphone());
                family.setWork(saveVO.getFatherWork());
                family.setFamilyFlag("0");
                familyList.add(family);
            }
            if (StringUtils.isNotBlank(saveVO.getRelationshipIdcard())) {
                PersonInfo personInfo =
                        this.savePerson(saveVO.getRelationshipIdcard().toUpperCase(), saveVO.getRelationshipCardType(), saveVO.getRelationshipName());
                saveVO.setRelationshipIdcard(saveVO.getRelationshipIdcard().toUpperCase());
                EduStudentEnrollFamily family = new EduStudentEnrollFamily();
                family.setStudentEnrollPreId(saveVO.getStudentEnrollPreId());
                family.setCardType(saveVO.getRelationshipCardType());
                family.setIdcard(saveVO.getRelationshipIdcard());
                family.setPersonId(personInfo.getPersonId());
                family.setFullName(saveVO.getRelationshipName());
                family.setRelationshipType(saveVO.getRelationshipType());
                family.setHouseFlag(BoolEnum.TRUE.getType());
                family.setCellphone(saveVO.getCellphone());
                family.setWork(saveVO.getWork());
                family.setFamilyFlag("0");
                familyList.add(family);
            }
        }
        eduStudentEnrollFamilyService.saveBatch(familyList);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0005", title = "预采集管理修改（PC）", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "edustudentenrollpre0005",
            operationName = "预采集管理修改（PC）",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO edit(EduStudentEnrollPreVO vo) {
        Boolean queryHistoryFlag = Boolean.TRUE.equals(eduDataTaskDetailService.verifyQueryHistory(vo.getYear(), STUDENT_ENROLL_PRE));
        if (queryHistoryFlag) {
            throw new AppException("历史数据无法修改");
        }
        String studentEnrollPreId = vo.getStudentEnrollPreId();
        if (ObjectUtils.isEmpty(studentEnrollPreId)) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        if (vo.getManagerFlag() == null) {
            vo.setManagerFlag(true);
        }
        if (!EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())
                &&!EnrollPreTypeEnum.xxlr.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            //为空默认按系统管理操作处理
            String orgId = SessionUtil.getSessionInfo().getOrgId();
            if (StringUtils.isBlank(orgId)) {
                throw new AppException("操作人员的所属组织不能为空");
            }
            String enrollPreType = EnrollPreTypeEnum.gl.getType();
            EduSchoolVO eduSchool = eduSchoolService.getDetail(orgId);
            if (eduSchool != null) {
                enrollPreType = EnrollPreTypeEnum.lr.getType();
            }
            if (EnrollPreTypeEnum.tstd.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                enrollPreType = EnrollPreTypeEnum.tstd.getType();
            }
            vo.setEnrollPreType(enrollPreType);
        }
        EduStudentEnrollPreKeyVO keyVO = new EduStudentEnrollPreKeyVO();
        keyVO.setStudentEnrollPreId(studentEnrollPreId);
        keyVO.setYear(vo.getYear());
        EduStudentEnrollPreVO oldEntity = this.getById(keyVO);
        //保存前校验
        checkSave(vo);

        vo.setType(SaveTypeEnum.UPDATE.getType());
        boolean authFlag = false;
        boolean changeFlag = false;
        if (!vo.getManagerFlag()) {
            if (!StrUtil.equals(vo.getFatherIdcard(), oldEntity.getFatherIdcard())
                    || !StrUtil.equals(vo.getFatherName(), oldEntity.getFatherName())
                    || !StrUtil.equals(vo.getMotherIdcard(), oldEntity.getMotherIdcard())
                    || !StrUtil.equals(vo.getMotherName(), oldEntity.getMotherName())
                    || !StrUtil.equals(vo.getFullName(), oldEntity.getFullName())
                    || !StrUtil.equals(vo.getIdcard(), oldEntity.getIdcard())
                    || !StrUtil.equals(vo.getRelationshipIdcard(), oldEntity.getRelationshipIdcard())
                    || !StrUtil.equals(vo.getRelationshipName(), oldEntity.getRelationshipName())
            ) {
                //家长端修改身份信息有变化，需要审核
                if (EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                    authFlag = true;
                }
                changeFlag = true;
            }
            if (!StrUtil.equals(vo.getFullName(), oldEntity.getFullName())) {
                //家长端修改身份信息有变化，需要审核
                if (EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                    authFlag = true;
                }
            }
        }

        if (!authFlag) {
            //判断学校采集的信息，家长不能更新关键信息

            vo.setAuthStatus(AuthStatusEnum.YES.getType());
            vo.setAuthUserId(SessionUtil.getUserId());
            vo.setAuthTime(new Date());
            if (vo.getManagerFlag()&&EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())){
                vo.setAuthRemarks("家长修改审核通过");
            }else if (vo.getManagerFlag() || !EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                vo.setAuthRemarks("学校或管理员修改审核通过");
            } else {
                vo.setAuthRemarks("个人非关键信息修改审核通过");
            }
            EduStudentEnrollPre eduStudentEnrollPre = Convert.convert(EduStudentEnrollPre.class, oldEntity);
            if (!StrUtil.equals(vo.getFullName(), oldEntity.getFullName())||!StrUtil.equals(vo.getIdcard(), oldEntity.getIdcard())) {
                PersonInfo personInfo = this.savePerson(vo.getIdcard(), vo.getCardType(), vo.getFullName());
                vo.setPersonId(personInfo.getPersonId());
            }
            if (changeFlag) {
                this.saveFamily(vo, true);
                vo.setBeforeFlag("0");
                vo.setCalculateFlag("0");
                vo.setHouseholdSyncFlag("0");
                vo.setHouseSyncFlag("0");
                vo.setNetsignSyncFlag("0");
                vo.setCbSyncFlag("0");
                vo.setQySyncFlag("0");
                vo.setJzzSyncFlag("0");
                vo.setFamilyFlag("0");
                vo.setConsistentFlag("0");
                if(StringUtils.isBlank(vo.getConsistentType())){
                    vo.setConsistentType("1");
                }
            }
            BeanUtil.copyProperties(vo, eduStudentEnrollPre);
            eduStudentEnrollPreService.updateById(eduStudentEnrollPre);
            if (vo.getManagerFlag()) {
                this.saveFamily(vo, true);
            }
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCachePreBefore(eduStudentEnrollPre.getStudentEnrollPreId());
        } else {

            vo.setAuthStatus(AuthStatusEnum.NODO.getType());
            vo.setAuthStatusName(AuthStatusEnum.NODO.getText());
            vo.setAuthRemarks("");
            vo.setAuthTime(null);
            if (changeFlag) {
                vo.setBeforeFlag("0");
                vo.setCalculateFlag("0");
                vo.setHouseholdSyncFlag("0");
                vo.setHouseSyncFlag("0");
                vo.setNetsignSyncFlag("0");
                vo.setCbSyncFlag("0");
                vo.setJzzSyncFlag("0");
                vo.setQySyncFlag("0");
                vo.setFamilyFlag("0");
                vo.setConsistentFlag("0");
                if (StringUtils.isBlank(vo.getConsistentType())) {
                    vo.setConsistentType("1");
                }
            }
            EduBusiEnrollPre eduBusiEnrollPre = Convert.convert(EduBusiEnrollPre.class, vo);

            eduBusiEnrollPreService.save(eduBusiEnrollPre);
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCachePreBefore(eduBusiEnrollPre.getStudentEnrollPreId());
            eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getMotherIdcard());
        }
        return vo;
    }


    @Override
    @OpApi(funcCode = "edustudentenrollpre0006", title = "预采集管理根据主键删除", funcType = FuncTypeEnum.delete)
    @SaveOplog(
            operationType = "edustudentenrollpre0006",
            operationName = "预采集管理删除",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void del(EduStudentEnrollPreKeyVO vo) {
        if (ObjectUtils.isEmpty(vo.getStudentEnrollPreId()) && vo.getBusiEnrollPreId() == null) {
            throw new AppException("传入需要删除的数据主键不能为空!");
        }
        if (!ObjectUtils.isEmpty(vo.getStudentEnrollPreId())) {
            EduStudentEnrollPre entity = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            if (ObjectUtils.isEmpty(entity)) {
                throw new AppException("未找到需要删除的信息!");
            }
            eduStudentEnrollPreService.removeById(vo.getStudentEnrollPreId());
            eduStudentEnrollFamilyService.removeByPreId(vo.getStudentEnrollPreId());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(entity.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(entity.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(entity.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCachePreBefore(entity.getStudentEnrollPreId());
        }
        if (vo.getBusiEnrollPreId() != null) {
            EduBusiEnrollPre entity = eduBusiEnrollPreService.getById(vo.getBusiEnrollPreId());
            if (ObjectUtils.isEmpty(entity)) {
                throw new AppException("未找到需要删除的信息!");
            }
            eduBusiEnrollPreService.removeById(vo.getBusiEnrollPreId());
        }

    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0007", title = "预采集管理exceld导入（PC）", funcType = FuncTypeEnum.insert)
    public ExcelReadVO readExcel(ExcelVO vo, MultipartFile file) {
        String areaCode = "";
        if (SessionUtil.getSessionInfo() != null) {
            areaCode = SessionUtil.getAreaCode();
        }
        //判断是否在经办业务期内
        eduHelper.checkOperation("2", "YW027", areaCode);
        ExcelReadVO excelReadVO = new ExcelReadVO();
        excelReadVO.setCount(0);
        ExcelModelVO excelModelVO = this.getModel(vo);
        InputStream in = null;
        try {
            in = file.getInputStream();
            List<Map<String, Object>> list = excelCommonHelper.readExcel(excelModelVO, in, true);

            List<Map<String, Object>> successList = new ArrayList<>();
            List<Map<String, Object>> errorList = new ArrayList<>();
            List<String> idcardList = new ArrayList<>();
            EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
            queryVO.setAreaCode(SessionUtil.getAreaCode());
            queryVO.setClassify("2");
            EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
            int year = eduOperationCacheVO.getYear();
            //获取预采集导入是否校验拟读学校
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("nd_school_area_code");
            String ndSchoolAreaCode = commonIntegration.getValueByKey(commonVO);
            List<String> ndSchoolAreaCodeList = Arrays.stream(ndSchoolAreaCode.split(",")).collect(Collectors.toList());
            for (Map<String, Object> map : list) {
                EduStudentEnrollPreVO enrollPreVo = JSON.parseObject(JSON.toJSONString(map), EduStudentEnrollPreVO.class);
                QueryWrapper<EduSchool> schoolQueryWrapper = new QueryWrapper<>();
                List<EduSchool> schoolList = eduSchoolService.list(schoolQueryWrapper);
                String remarks = "";
                boolean flag = false;
                if (StringUtils.isBlank(enrollPreVo.getCardType())) {
                    enrollPreVo.setCardType(CardTypeEnum.idcard.getType());
                    enrollPreVo.setCardTypeName(CardTypeEnum.idcard.getName());
                } else if (StringUtils.isBlank(enrollPreVo.getCardType().trim())) {
                    enrollPreVo.setCardType(CardTypeEnum.idcard.getType());
                    enrollPreVo.setCardTypeName(CardTypeEnum.idcard.getName());
                } else {
                    //导入是中文情况下处理成数据字典
                    if (Validator.isChinese(enrollPreVo.getCardType().trim())) {
                        DictQueryVO dictQueryVO = new DictQueryVO();
                        dictQueryVO.setDictField("cardType");
                        dictQueryVO.setDictValue(enrollPreVo.getCardType().trim());
                        String key = dictIntegration.getValue(dictQueryVO);
                        if (StringUtils.isBlank(key)) {
                            remarks += "学生证件类型数据格式不对！";
                            flag = true;
                        }
                        enrollPreVo.setCardType(key);
                    }
                }
                enrollPreVo.setIdcard(enrollPreVo.getIdcard().trim().toUpperCase());
                if (CardTypeEnum.idcard.getType().equals(enrollPreVo.getCardType()) && !IdcardUtil.isValidCard(enrollPreVo.getIdcard())) {
                    remarks += "学生身份证有误！";
                    flag = true;
                }
                if (idcardList.contains(enrollPreVo.getIdcard())) {
                    remarks += "存在重复学生身份证！";
                    flag = true;
                } else {
                    idcardList.add(enrollPreVo.getIdcard());
                }

                if (ObjectUtils.isEmpty(enrollPreVo.getFullName())) {
                    remarks += "学生姓名不能为空！";
                    flag = true;
                } else {
                    enrollPreVo.setFullName(
                            Validator.isChinese(enrollPreVo.getFullName())
                                    ? enrollPreVo.getFullName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                    : enrollPreVo.getFullName().trim());
                }
                if(StringUtils.isNotBlank(enrollPreVo.getFatherName())){
                    if (enrollPreVo.getFatherName().equals(enrollPreVo.getFullName())) {
                        remarks +="父亲（监护人）姓名不能与学生姓名相同！";
                        flag = true;
                    }
                }
                if(StringUtils.isNotBlank(enrollPreVo.getMotherName())){
                    if (enrollPreVo.getMotherName().equals(enrollPreVo.getFullName())) {
                        remarks +="母亲姓名不能与学生姓名相同！";
                        flag = true;
                    }
                }
                if(StringUtils.isNotBlank(enrollPreVo.getFatherName())&&StringUtils.isNotBlank(enrollPreVo.getMotherName())){
                    if (enrollPreVo.getMotherName().equals(enrollPreVo.getFatherName())) {
                        remarks +="父亲（监护人）姓名不能与母亲姓名相同！";
                        flag = true;
                    }
                }
                if(StringUtils.isNotBlank(enrollPreVo.getFatherIdcard())&&StringUtils.isNotBlank(enrollPreVo.getMotherIdcard())){
                    if (enrollPreVo.getFatherIdcard().equals(enrollPreVo.getMotherIdcard())) {
                        remarks +="父亲（监护人）证件号码不能与母亲证件号码相同！";
                        flag = true;
                    }
                }
                if(StringUtils.isNotBlank(enrollPreVo.getFatherIdcard())){
                    if (enrollPreVo.getFatherIdcard().equals(enrollPreVo.getIdcard())) {
                        remarks +="父亲（监护人）证件号码不能与学生证件号码相同！";
                        flag = true;
                    }
                }
                if(StringUtils.isNotBlank(enrollPreVo.getMotherIdcard())){
                    if (enrollPreVo.getMotherIdcard().equals(enrollPreVo.getIdcard())) {
                        remarks +="母亲证件号码不能与学生证件号码相同！";
                        flag = true;
                    }
                }
                if (!CardTypeEnum.idcard.getType().equals(enrollPreVo.getCardType())) {
                    if (StringUtils.isBlank(enrollPreVo.getSex())) {
                        remarks += "选择其他证件类型时学生性别不能为空！";
                        flag = true;
                    }
                    if (StringUtils.isBlank(enrollPreVo.getSex().trim())) {
                        remarks += "选择其他证件类型时学生性别不能为空！";
                        flag = true;
                    }
                    if (Validator.isChinese(enrollPreVo.getSex().trim())) {
                        DictQueryVO dictQueryVO = new DictQueryVO();
                        dictQueryVO.setDictField("sex");
                        dictQueryVO.setDictValue(enrollPreVo.getSex().trim());
                        String key = dictIntegration.getValue(dictQueryVO);
                        if (StringUtils.isBlank(key)) {
                            remarks += "性别数据格式不对！";
                            flag = true;
                        }
                        enrollPreVo.setSex(key);
                    }

                    if (StringUtils.isBlank(enrollPreVo.getBirthYmd())) {
                        remarks += "选择其他证件类型时学生出生日期不能为空！";
                        flag = true;
                    } else {
                        if (enrollPreVo.getBirthYmd().length() != 8 || enrollPreVo.getBirthYmd().length() != 10) {
                            remarks += "出生日期格式不正确！正确格式：如2022-01-01或20220101";
                            flag = true;
                        }

                        try {
                            enrollPreVo.setBirthYmd(DateUtil.format(DateUtil.parse(enrollPreVo.getBirthYmd(), "yyyyMMdd"), "yyyyMMdd"));
                        } catch (Exception e) {
                            remarks += "出生日期格式不正确！正确格式：如2022-01-01或20220101";
                            flag = true;
                        }
                    }

                } else {
                    if(IdcardUtil.isValidCard(enrollPreVo.getIdcard())) {
                        enrollPreVo.setBirthYmd(IdcardUtil.getBirth(enrollPreVo.getIdcard()));
                        int gender = IdcardUtil.getGenderByIdCard(enrollPreVo.getIdcard());
                        if (gender == 1) {
                            // 男
                            enrollPreVo.setSex("1");
                        } else {
                            // 女
                            enrollPreVo.setSex("2");
                        }
                    }
                }

                boolean rFlag = false;
                if (!ObjectUtils.isEmpty(enrollPreVo.getFatherIdcard()) && StringUtils.isNotBlank(enrollPreVo.getFatherIdcard().trim())) {
                    if (StringUtils.isBlank(enrollPreVo.getFatherCardType())) {
                        enrollPreVo.setFatherCardType(CardTypeEnum.idcard.getType());
                    } else if (StringUtils.isBlank(enrollPreVo.getFatherCardType().trim())) {
                        enrollPreVo.setFatherCardType(CardTypeEnum.idcard.getType());
                    } else {
                        //导入是中文情况下处理成数据字典
                        if (StringUtils.isNotBlank(enrollPreVo.getFatherCardType().trim()) && Validator.isChinese(enrollPreVo.getFatherCardType().trim())) {
                            DictQueryVO dictQueryVO = new DictQueryVO();
                            dictQueryVO.setDictField("cardType");
                            dictQueryVO.setDictValue(enrollPreVo.getFatherCardType().trim());
                            String key = dictIntegration.getValue(dictQueryVO);
                            if (StringUtils.isBlank(key)) {
                                remarks += "父亲（监护人）证件类型数据格式不对！";
                                flag = true;
                            }
                            enrollPreVo.setFatherCardType(key);
                        }
                    }
                    enrollPreVo.setFatherIdcard(enrollPreVo.getFatherIdcard().trim().toUpperCase());
                    if (CardTypeEnum.idcard.getType().equals(enrollPreVo.getFatherCardType()) && !IdcardUtil.isValidCard(enrollPreVo.getFatherIdcard())) {
                        remarks += "父亲（监护人）身份证有误！";
                        flag = true;
                    }
                    if (ObjectUtils.isEmpty(enrollPreVo.getFatherName())) {
                        remarks += ("父亲（监护人）姓名不能为空！");
                        flag = true;
                    } else {
                        enrollPreVo.setFatherName(
                                Validator.isChinese(enrollPreVo.getFatherName())
                                        ? enrollPreVo.getFatherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                        : enrollPreVo.getFatherName().trim());
                    }
                    if (!ObjectUtils.isEmpty(enrollPreVo.getFatherCellphone()) && !PhoneUtil.isMobile(enrollPreVo.getFatherCellphone())) {
                        remarks += "父亲（监护人）手机号码不正确！";
                        flag = true;
                    }
                    rFlag = true;
                }

                if (!ObjectUtils.isEmpty(enrollPreVo.getMotherIdcard()) && StringUtils.isNotBlank(enrollPreVo.getMotherIdcard().trim())) {
                    if (StringUtils.isBlank(enrollPreVo.getMotherCardType())) {
                        enrollPreVo.setMotherCardType(CardTypeEnum.idcard.getType());
                    } else if (StringUtils.isBlank(enrollPreVo.getMotherCardType().trim())) {
                        enrollPreVo.setMotherCardType(CardTypeEnum.idcard.getType());
                    } else {
                        //导入是中文情况下处理成数据字典
                        if (Validator.isChinese(enrollPreVo.getMotherCardType().trim())) {
                            DictQueryVO dictQueryVO = new DictQueryVO();
                            dictQueryVO.setDictField("cardType");
                            dictQueryVO.setDictValue(enrollPreVo.getMotherCardType().trim());
                            String key = dictIntegration.getValue(dictQueryVO);
                            if (StringUtils.isBlank(key)) {
                                remarks += "父亲（监护人）证件类型数据格式不对！";
                                flag = true;
                            }
                            enrollPreVo.setMotherCardType(key);
                        }
                    }
                    enrollPreVo.setMotherIdcard(enrollPreVo.getMotherIdcard().trim().toUpperCase());
                    if (CardTypeEnum.idcard.getType().equals(enrollPreVo.getMotherCardType()) && !IdcardUtil.isValidCard(enrollPreVo.getMotherIdcard())) {
                        remarks += "母亲身份证有误！";
                        flag = true;
                    }
                    if (ObjectUtils.isEmpty(enrollPreVo.getMotherName())) {
                        remarks += ("母亲姓名不能为空！");
                        flag = true;
                    } else {
                        enrollPreVo.setMotherName(
                                Validator.isChinese(enrollPreVo.getMotherName())
                                        ? enrollPreVo.getMotherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                        : enrollPreVo.getMotherName().trim());
                    }
                    if (!ObjectUtils.isEmpty(enrollPreVo.getMotherCellphone()) && !PhoneUtil.isMobile(enrollPreVo.getMotherCellphone())) {
                        remarks += "母亲手机号码不正确！";
                        flag = true;
                    }
                    rFlag = true;
                }

                if (!ObjectUtils.isEmpty(enrollPreVo.getRelationshipIdcard()) && StringUtils.isNotBlank(enrollPreVo.getRelationshipIdcard().trim())) {
                    if (StringUtils.isBlank(enrollPreVo.getRelationshipCardType())) {
                        enrollPreVo.setRelationshipCardType(CardTypeEnum.idcard.getType());
                    } else if (StringUtils.isBlank(enrollPreVo.getRelationshipCardType().trim())) {
                        enrollPreVo.setRelationshipCardType(CardTypeEnum.idcard.getType());
                    } else {
                        //导入是中文情况下处理成数据字典
                        if (Validator.isChinese(enrollPreVo.getRelationshipCardType().trim())) {
                            DictQueryVO dictQueryVO = new DictQueryVO();
                            dictQueryVO.setDictField("cardType");
                            dictQueryVO.setDictValue(enrollPreVo.getRelationshipCardType().trim());
                            String key = dictIntegration.getValue(dictQueryVO);
                            if (StringUtils.isBlank(key)) {
                                remarks += "父亲（监护人）证件类型数据格式不对！";
                                flag = true;
                            }
                            enrollPreVo.setRelationshipCardType(key);
                        }
                    }
                    enrollPreVo.setRelationshipIdcard(enrollPreVo.getRelationshipIdcard().trim().toUpperCase());
                    if (CardTypeEnum.idcard.getType().equals(enrollPreVo.getRelationshipCardType()) && !IdcardUtil.isValidCard(enrollPreVo.getRelationshipIdcard())) {
                        remarks += "监护人身份证有误！";
                        flag = true;
                    }
                    if (ObjectUtils.isEmpty(enrollPreVo.getRelationshipName())) {
                        remarks += "监护人姓名不能为空！";
                        flag = true;
                    } else {
                        enrollPreVo.setRelationshipName(
                                Validator.isChinese(enrollPreVo.getRelationshipName())
                                        ? enrollPreVo.getRelationshipName().replace(" ", "").trim()
                                        : enrollPreVo.getRelationshipName().trim());
                    }
                    if (StringUtils.isBlank(enrollPreVo.getRelationshipType())) {
                        remarks += "监护人与学生关系不能为空！";
                        flag = true;
                    }
                    if (!ObjectUtils.isEmpty(enrollPreVo.getCellphone()) && !PhoneUtil.isMobile(enrollPreVo.getCellphone())) {
                        remarks += "监护人手机号码不正确！";
                        flag = true;
                    }
                    rFlag = true;
                }
                if (!rFlag) {
                    remarks += "父亲（监护人）、母亲信息至少填一个！";
                    flag = true;
                }


                if (!flag) {
                    int age = 0;
                    if (CardTypeEnum.idcard.getType().equalsIgnoreCase(enrollPreVo.getCardType())) {
                        age = IdcardUtil.getAgeByIdCard(
                                enrollPreVo.getIdcard(),
                                DateUtil.parse(year + "0901", "yyyyMMdd"));
                    } else {
                        age = DateUtil.age(DateUtil.parse(enrollPreVo.getBirthYmd(), "yyyyMMdd"), DateUtil.parse(year + "0901", "yyyyMMdd"));
                    }

                    if (age >= 6 && age <= 7) {
                        enrollPreVo.setSchoolCategory(SchoolCategoryEnum.PRIMARY.getType());
                    } else if (age >= 11 && age <= 14) {
                        enrollPreVo.setSchoolCategory(SchoolCategoryEnum.JUNIOR.getType());
                    } else {
                        remarks += "学生不在适龄年龄段！";
                        flag = true;
                    }
                    enrollPreVo.setAge(age);
                }
                if (StringUtils.isNotBlank(enrollPreVo.getFatherIdcard()) && StringUtils.isNotBlank(enrollPreVo.getMotherIdcard())) {
                    if (enrollPreVo.getFatherIdcard().equalsIgnoreCase(enrollPreVo.getMotherIdcard())) {
                        remarks += "提交的父亲（监护人）和母亲证件号码相同！";
                        flag = true;
                    }
                }
                AtomicBoolean schoolFlag = new AtomicBoolean(false);
                schoolList.forEach(
                        school -> {
                            if (!ObjectUtils.isEmpty(enrollPreVo.getShortName())
                                    && school.getShortName()
                                    .replaceAll("（", "(")
                                    .replaceAll("）", ")")
                                    .equals(
                                            enrollPreVo.getShortName()
                                                    .replaceAll("（", "(")
                                                    .replaceAll("）", ")"))) {
                                schoolFlag.set(true);
                                enrollPreVo.setSchoolId(school.getOrgId());
                            }
                            if (!ObjectUtils.isEmpty(enrollPreVo.getSchoolName())
                                    && school.getSchoolName()
                                    .replaceAll("（", "(")
                                    .replaceAll("）", ")")
                                    .equals(
                                            enrollPreVo.getSchoolName()
                                                    .replaceAll("（", "(")
                                                    .replaceAll("）", ")"))) {
                                schoolFlag.set(true);
                                enrollPreVo.setSchoolId(school.getOrgId());
                            }

                        });
                if (ndSchoolAreaCodeList.contains(areaCode)){
                    if (!schoolFlag.get()) {
                        remarks += "找不到拟就读公办学校";
                        flag = true;
                    }
                }

                if (flag) {
                    enrollPreVo.setRemarks(remarks);
                    errorList.add(JSON.parseObject(JSON.toJSONString(enrollPreVo), Map.class));
                } else {
                    successList.add(JSON.parseObject(JSON.toJSONString(enrollPreVo), Map.class));
                }

            }

            excelReadVO.setCount(successList.size() + errorList.size());
            excelReadVO.setSuccessCount(successList.size());
            excelReadVO.setSuccessList(successList);
            excelReadVO.setErrorList(errorList);
            excelReadVO.setErrorCount(errorList.size());


        } catch (AppException appEx) {
            throw appEx;
        } catch (IOException e) {
            throw new AppException("读取文件异常:" + e.getMessage());
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return excelReadVO;


    }


    @Override
    @OpApi(funcCode = "edustudentenrollpre0008", title = "预采集模板下载（PC）", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void downloadModel(ExcelVO vo, HttpServletResponse response) {
        Map<String, List<SelectVO>> dictMap = new HashMap<>();
        dictMap.put("schoolName", getSchoolDictMap());
        vo.setDictMap(dictMap);
        excelIntegration.downloadModel(vo, response);

    }

    @Override
    @OpApi(funcCode = "studentInfo0001", title = "学生搜索", funcType = FuncTypeEnum.query)
    public PageInfo<StudentInfoSelectVO> searchStudentSelect(StudentInfoSearchVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(20);
        }

        Integer pageNum = vo.getPageNum();
        Integer pageSize = vo.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StudentInfoSelectVO> list = eduStudentEnrollPreService.searchPersonSelect(vo);


        PageInfo<StudentInfoSelectVO> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0009", title = "预采集管理-预采集人员新增", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "edustudentenrollpre0009",
            operationName = "预采集人员新增（PC）",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO add(EduStudentEnrollPreVO vo) {

        if (StringUtils.isBlank(vo.getEnrollPreType())) {
            String orgId = SessionUtil.getOrgId();
            String submitterId = SessionUtil.getUserId();
            String submitterName = SessionUtil.getFullName();
            if (StringUtils.isBlank(orgId)) {
                throw new AppException("操作人员的所属组织不能为空");
            }
            String enrollPreType = EnrollPreTypeEnum.gl.getType();
            EduSchoolVO eduSchool = eduSchoolService.getDetail(orgId);
            if (eduSchool != null) {
                enrollPreType = EnrollPreTypeEnum.lr.getType();
            }
            vo.setEnrollPreType(enrollPreType);
            vo.setOrgId(orgId);
            vo.setSubmitterId(submitterId);
            vo.setSubmitterName(submitterName);
        }
        if (vo.getManagerFlag() == null) {
            vo.setManagerFlag(true);
        }
        checkSave(vo);
        vo.setStudentEnrollPreId(IdUtil.simpleUUID());
        if (StringUtils.isNotBlank(vo.getSchoolId())) {
            EduSchoolVO school = eduSchoolService.getDetail(vo.getSchoolId());
            if (school != null) {
                vo.setShortName(school.getShortName());
            }
        }

        if (!EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            vo.setAuthStatus(AuthStatusEnum.YES.getType());
            vo.setAuthRemarks("学校或管理员修改审核通过");
            vo.setAuthUserId(SessionUtil.getUserId());
            vo.setAuthTime(new Date());
            PersonInfo personInfo = this.savePerson(vo.getIdcard(), vo.getCardType(), vo.getFullName());
            vo.setPersonId(personInfo.getPersonId());
            this.saveFamily(vo, false);
            EduStudentEnrollPre eduStudentEnrollPre = Convert.convert(EduStudentEnrollPre.class, vo);
            eduStudentEnrollPreService.save(eduStudentEnrollPre);
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getFatherIdcard());
            eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getMotherIdcard());
            eduEnrollClearCacheHelper.clearCachePreBefore(eduStudentEnrollPre.getStudentEnrollPreId());
        } else {
            if (vo.getManagerFlag()){
                vo.setAuthStatus(AuthStatusEnum.YES.getType());
                vo.setAuthRemarks("家长新增审核通过");
                vo.setAuthTime(new Date());
                vo.setAuthUserId(SessionUtil.getUserId());
                PersonInfo personInfo = this.savePerson(vo.getIdcard(), vo.getCardType(), vo.getFullName());
                vo.setPersonId(personInfo.getPersonId());
                this.saveFamily(vo, false);
                EduStudentEnrollPre eduStudentEnrollPre = Convert.convert(EduStudentEnrollPre.class, vo);
                eduStudentEnrollPreService.save(eduStudentEnrollPre);
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduStudentEnrollPre.getMotherIdcard());
                eduEnrollClearCacheHelper.clearCachePreBefore(eduStudentEnrollPre.getStudentEnrollPreId());
            }else {
                vo.setAuthStatus(AuthStatusEnum.NODO.getType());
                vo.setAuthRemarks(null);
                vo.setAuthTime(null);
                vo.setAuthUserId(null);
                EduBusiEnrollPre eduBusiEnrollPre = Convert.convert(EduBusiEnrollPre.class, vo);
                eduBusiEnrollPre.setStudentEnrollPreId(null);
                eduBusiEnrollPreService.save(eduBusiEnrollPre);
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getMotherIdcard());
                eduEnrollClearCacheHelper.clearCachePreBefore(eduBusiEnrollPre.getStudentEnrollPreId());
                eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getIdcard());
                eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getFatherIdcard());
                eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getMotherIdcard());
            }
        }

        return vo;
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0010", title = "家长端准新生登记保存", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "edustudentenrollpre0010",
            operationName = "家长端准新生登记保存",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO savePre(EduStudentEnrollPreVO vo) {
        vo.setEnrollPreType(EnrollPreTypeEnum.dj.getType());
        vo.setType(SaveTypeEnum.INSERT.getType());
        vo.setManagerFlag(false);
        return this.add(vo);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpreJh0010", title = "家长端准新生登记保存金华模式", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "edustudentenrollpreJh0010",
            operationName = "家长端准新生登记保存金华模式",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO savePreJh(EduStudentEnrollPreVO vo) {
        //新增判断登记和修改需要家长一方
        checkDj(vo);
        vo.setEnrollPreType(EnrollPreTypeEnum.dj.getType());
        vo.setType(SaveTypeEnum.INSERT.getType());
        vo.setManagerFlag(true);
        return this.add(vo);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpreJh0011", title = "家长端新生信息修改金华模式", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "edustudentenrollpreJh0011",
            operationName = "家长端新生信息修改金华模式",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO editPreJh(EduStudentEnrollPreVO vo) {
        //新增判断登记和修改需要家长一方
        checkDj(vo);
        vo.setEnrollPreType(EnrollPreTypeEnum.dj.getType());
        vo.setManagerFlag(true);
        if (StringUtils.isNotBlank(vo.getStudentEnrollPreId())) {
            return this.edit(vo);
        } else {
            vo.setBusiEnrollPreId(null);
            return this.add(vo);
        }
    }
    private void checkDj(EduStudentEnrollPreVO vo){
        String jzIdcard=SessionUtil.getSessionInfo()!=null?SessionUtil.getSessionInfo().getIdcard():"";
        if (StringUtils.isNotBlank(jzIdcard)){
            boolean flag=true;
            if(StringUtils.isNotBlank(vo.getMotherIdcard())){
                if(vo.getMotherIdcard().toUpperCase().equalsIgnoreCase(jzIdcard.toUpperCase())){
                    flag=false;
                }
            }
            if(StringUtils.isNotBlank(vo.getFatherIdcard())){
                if(vo.getFatherIdcard().toUpperCase().equalsIgnoreCase(jzIdcard.toUpperCase())){
                    flag=false;
                }
            }
            if (flag){
                throw new AppException("请使用孩子父母或监护人的浙里办账号进行子女信息登记或修改");
            }
        }
    }
    @Override
    @OpApi(funcCode = "edustudentenrollpre0017", title = "手机端-准新生扫码登记", funcType = FuncTypeEnum.insert, publicFlag = BoolEnum.TRUE)
    public EduStudentEnrollPreVO scanningSavePre(EduStudentEnrollPreVO vo) {
        vo.setEnrollPreType(EnrollPreTypeEnum.dj.getType());
        vo.setType(SaveTypeEnum.INSERT.getType());
        vo.setManagerFlag(false);
        return this.add(vo);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0018", title = "手机端-根据身份证查询本年度学生登记信息是否存在", funcType = FuncTypeEnum.query, publicFlag = BoolEnum.TRUE)
    public String checkByIdcard(CheckByIdcardVO vo) {
        if (StringUtils.isBlank(vo.getIdcard())) {
            throw new AppException("证件号码不能为空");
        }
        QueryWrapper<EduBusiEnrollPre> busiEnrollPreQueryWrapper = new QueryWrapper<>();
        busiEnrollPreQueryWrapper.lambda().eq(EduBusiEnrollPre::getYear, eduHelper.thisYear())
                .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NODO.getType())
                .eq(EduBusiEnrollPre::getIdcard, vo.getIdcard());
        if (eduBusiEnrollPreService.count(busiEnrollPreQueryWrapper) > 0) {
            return "1";//存在待审核数据显示身份证二维码
        }
        QueryWrapper<EduStudentEnrollPre> preQueryWrapper = new QueryWrapper<>();
        preQueryWrapper.lambda().eq(EduStudentEnrollPre::getYear, eduHelper.thisYear())
                .eq(EduStudentEnrollPre::getIdcard, vo.getIdcard());
        if (eduStudentEnrollPreService.count(preQueryWrapper) > 0) {
            return "2";//已审核通过，提示是否进行修改
        }
        return "3";//不存在准新生信息，需要登记
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0011", title = "家长端新生信息修改", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "edustudentenrollpre0011",
            operationName = "家长端新生信息修改",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO editPre(EduStudentEnrollPreVO vo) {
        vo.setEnrollPreType(EnrollPreTypeEnum.dj.getType());
        vo.setManagerFlag(false);
        if (StringUtils.isNotBlank(vo.getStudentEnrollPreId())) {
            return this.edit(vo);
        } else {
            vo.setBusiEnrollPreId(null);
            return this.add(vo);
        }

    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0012", title = "预采集管理新生信息审核", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "edustudentenrollpre0012",
            operationName = "预采集管理新生信息审核",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public void auditEnrollPre(EnrollPreAuditVO vo) {
        Long id = vo.getBusiEnrollPreId();
        EduBusiEnrollPre busiEnrollPre = eduBusiEnrollPreService.getById(id);
        if (busiEnrollPre == null) {
            throw new AppException("待审核的数据不存在");
        }
        if (!AuthStatusEnum.NODO.getType().equalsIgnoreCase(busiEnrollPre.getAuthStatus())) {
            throw new AppException("该业务已审核，不能重复操作");
        }
        busiEnrollPre.setAuthStatus(vo.getAuthStatus());
        busiEnrollPre.setAuthRemarks(vo.getAuthRemarks());
        busiEnrollPre.setAuthTime(new Date());
        busiEnrollPre.setAuthUserId(SessionUtil.getUserId());


        if (vo.getAuthStatus().equals(AuthStatusEnum.YES.getType())) {
            if (StringUtils.isBlank(busiEnrollPre.getStudentEnrollPreId())) {
                busiEnrollPre.setStudentEnrollPreId(IdUtil.simpleUUID());
            }
            EduStudentEnrollPreVO saveVO = Convert.convert(EduStudentEnrollPreVO.class, busiEnrollPre);
            if (busiEnrollPre.getType().equalsIgnoreCase(SaveTypeEnum.INSERT.getType())) {
                PersonInfo personInfo = this.savePerson(saveVO.getIdcard(), saveVO.getCardType(), saveVO.getFullName());
                saveVO.setPersonId(personInfo.getPersonId());
                this.saveFamily(saveVO, false);
                EduStudentEnrollPre enrollPre =
                        Convert.convert(EduStudentEnrollPre.class, saveVO);
                eduStudentEnrollPreService.save(enrollPre);
            } else {
                EduStudentEnrollPreKeyVO keyVO = new EduStudentEnrollPreKeyVO();
                keyVO.setStudentEnrollPreId(busiEnrollPre.getStudentEnrollPreId());
                EduStudentEnrollPreVO oldEntity = this.getById(keyVO);
                if (!StrUtil.equals(saveVO.getFatherIdcard(), oldEntity.getFatherIdcard())
                        || !StrUtil.equals(saveVO.getFatherName(), oldEntity.getFatherName())
                        || !StrUtil.equals(saveVO.getMotherIdcard(), oldEntity.getMotherIdcard())
                        || !StrUtil.equals(saveVO.getMotherName(), oldEntity.getMotherName())
                        || !StrUtil.equals(saveVO.getRelationshipIdcard(), oldEntity.getRelationshipIdcard())
                        || !StrUtil.equals(saveVO.getRelationshipName(), oldEntity.getRelationshipName())
                ) {
                    this.saveFamily(saveVO, true);
                }
                if (!StrUtil.equals(saveVO.getFullName(), oldEntity.getFullName())) {
                    PersonInfo personInfo = this.savePerson(saveVO.getIdcard(), saveVO.getCardType(), saveVO.getFullName());
                    saveVO.setPersonId(personInfo.getPersonId());
                }
                EduStudentEnrollPre enrollPre =
                        Convert.convert(EduStudentEnrollPre.class, saveVO);
                enrollPre.setBeforeFlag("0");
                enrollPre.setCalculateFlag("0");
                enrollPre.setHouseholdSyncFlag("0");
                enrollPre.setHouseSyncFlag("0");
                enrollPre.setNetsignSyncFlag("0");
                enrollPre.setCbSyncFlag("0");
                enrollPre.setQySyncFlag("0");
                enrollPre.setJzzSyncFlag("0");
                enrollPre.setFamilyFlag("0");
                enrollPre.setConsistentFlag("0");
                if(StringUtils.isBlank(enrollPre.getConsistentType())){
                    enrollPre.setConsistentType("1");
                }
                eduStudentEnrollPreService.updateById(enrollPre);
            }
        }
        eduBusiEnrollPreService.updateById(busiEnrollPre);
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(busiEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(busiEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(busiEnrollPre.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCachePreBefore(busiEnrollPre.getStudentEnrollPreId());
        eduEnrollClearCacheHelper.clearCacheMyApply(busiEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyApply(busiEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyApply(busiEnrollPre.getMotherIdcard());
    }


    @Override
    @OpApi(funcCode = "edustudentenrollpre0013", title = "预采集错误数据下载", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void downloadErrorExcel(EnrollPreFileVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        Map<String, List<SelectVO>> dictMap = new HashMap<>();
        dictMap.put("schoolName", getSchoolDictMap());
        excelVO.setDictMap(dictMap);

        ExcelModelVO excelModelVO = getModel(excelVO);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }

        EduSchoolVacancyQueryVO queryVO = new EduSchoolVacancyQueryVO();
        List<Object> errorList = Convert.toList(Object.class, vo.getErrorList());

        excelCommonHelper.downloadExcelBean(excelModelVO, errorList, fileName, response);


    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0014", title = "预采集信息导出", funcType = FuncTypeEnum.other, checkPrivilege = BoolEnum.FALSE)
    public void downloadData(EduStudentEnrollPreQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0015", title = "家长端获取我的当年适龄子女", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public List<EduStudentEnrollPreVO> getMyChilds(AreaControlVO baseVO) {
        String userId = SessionUtil.getUserId();
        String idcard = SessionUtil.getSessionInfo() == null ? null : SessionUtil.getSessionInfo().getIdcard();
        if (StringUtils.isBlank(idcard)) {
            throw new AppException("用户的证件号码不能为空");
        }
        String key = idcard;
        Cache<String, List<EduStudentEnrollPreVO>> cache = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE, CacheType.BOTH, Duration.ofHours(6), Duration.ofSeconds(20));
        List<EduStudentEnrollPreVO> value = cache.get(key);
        if (value != null) {
            return value;
        }
        List<String> areaCodeList=new ArrayList<>();
        if (StringUtils.isBlank(baseVO.getAreaCode())) {
            //获取当前部署行政区划
            String areaCode = eduHelper.thisAreaCode();
            if (StringUtils.isBlank(areaCode)) {
                throw new AppException("系统参数中当前部署行政区划不能为空");
            }
            baseVO.setAreaCode(areaCode);
            DictAreaVO dictAreaVO = new DictAreaVO();
            List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
            if(!CollectionUtils.isEmpty(districtByOrg)){
                areaCodeList=districtByOrg.stream().map(SelectVO::getDictKey).distinct().collect(Collectors.toList());
            }else{
                areaCodeList.add(areaCode);
            }
        }else{
            areaCodeList.add(baseVO.getAreaCode());
        }
        CommonVO commonTestVO=new CommonVO();
        commonTestVO.setParamKey("imitate_flag");
        String mnFlagStr=commonIntegration.getValueByKey(commonTestVO);

        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setOperating("YW025");
        queryVO.setAreaCode(baseVO.getAreaCode());
        queryVO.setClassify("2");
        EduOperationCacheDetailVO hjOption = eduSystemConfigIntegration.getEduOperationOne(queryVO);
        int year = hjOption.getYear();
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        //已采集数据
        studentEnrollPreQueryWrapper
                .lambda()
                .eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getSubmitterId, userId)
                                    .or()
                                    .eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                        }).orderByAsc(EduStudentEnrollPre::getIdcard);
        List<EduStudentEnrollPre> queryList =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        List<String> notidcardList = new ArrayList<>();
        List<EduStudentEnrollPreVO> resList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(queryList)) {
            Long householdEndTime = null;
            if (hjOption != null && hjOption.getEndTime() != null) {
                householdEndTime = hjOption.getEndTime().getTime() / 1000;
            }
            //获取报名情况
            List<String> enrollStatusList = new ArrayList<>();
            enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
            final Long endTime = householdEndTime;


            for (EduStudentEnrollPre pre : queryList) {
                EduStudentEnrollPreVO item = Convert.convert(EduStudentEnrollPreVO.class, pre);
                String schoolId = item.getSchoolId();
                if (StringUtils.isNotBlank(schoolId)) {
                    EduSchoolVO eduSchool = eduSchoolService.getDetail(schoolId);
                    item.setSchoolName(eduSchool.getSchoolName());
                }
                if (StringUtils.isBlank(item.getCardType())) {
                    item.setCardType(CardTypeEnum.idcard.getType());
                }
                if (StringUtils.isBlank(item.getFatherCardType())) {
                    item.setFatherCardType(CardTypeEnum.idcard.getType());
                }
                if (StringUtils.isBlank(item.getMotherCardType())) {
                    item.setMotherCardType(CardTypeEnum.idcard.getType());
                }
                notidcardList.add(item.getIdcard());
                QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                householdQueryWrapper
                        .lambda()
                        .eq(EduHousehold::getIdcard, item.getIdcard())
                        .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                        .in(EduHousehold::getAreaCode, areaCodeList)
                        .eq(EduHousehold::getYear, year)
                        .orderByDesc(EduHousehold::getQysj)
                        .last("limit 1");
                EduHousehold household = eduHouseholdService.getOne(householdQueryWrapper);
                boolean canEnrollFlag = false;
                if (!ObjectUtils.isEmpty(household)) {
                    QueryWrapper<EduComplaint> queryWrapper = new QueryWrapper<>();
                    queryWrapper.lambda().select(EduComplaint::getHandleStatus, EduComplaint::getOtherId).eq(EduComplaint::getType, ComplaintTypeEnum.hjxq.getType())
                            .eq(EduComplaint::getHandleStatus, BoolEnum.FALSE.getType())
                            .eq(EduComplaint::getOtherId, household.getHouseholdId());
                    List<EduComplaint> complaints = eduComplaintService.list(queryWrapper);
                    if (!CollectionUtils.isEmpty(complaints)) {
                        item.setHouseholdHandleStatus(complaints.get(0).getHandleStatus());
                    }
                    item.setHouseholdId(household.getHouseholdId());
                    item.setStreet(household.getStreet());
                    if (StringUtils.isBlank(item.getHouseholdPlace())) {
                        item.setHouseholdPlace(household.getAddress());
                    }
                    item.setRelation(household.getRelation());
                    item.setAccountType(household.getAccountType());
                    item.setHouseholdAddress(household.getAddress());
                    item.setHouseholdTime(household.getUpdateTime());
                    if (endTime != null && StringUtils.isNotBlank(household.getAddressId())) {
                        Boolean attendFlag = true;
                        if (endTime != null && household.getQysj() != null) {
                            Long qysj = DateUtil.parse(household.getQysj()).getTime() / 1000;
                            if (qysj > endTime) {
                                attendFlag = false;
                            }
                        }
                        SchoolDistrictQueryVO xqQuery = new SchoolDistrictQueryVO();
                        xqQuery.setAddressId(household.getAddressId());
                        xqQuery.setSchoolCategory(item.getSchoolCategory());
                        List<SchoolDistrictVO> schoolDistrictVOList = eduAddressSchoolService.getSchoolInfo(xqQuery);
                        if (!CollectionUtils.isEmpty(schoolDistrictVOList)) {
                            dictHelper.valueToName(schoolDistrictVOList, Arrays.asList(SchoolDictEnum.values()));
                            for (SchoolDistrictVO schoolDistrictVO : schoolDistrictVOList) {
                                if (item.getSchoolCategory().equals(schoolDistrictVO.getSchoolCategory())) {
                                    schoolDistrictVO.setAgeFlag(true);
                                } else {
                                    schoolDistrictVO.setAgeFlag(false);
                                }
                                //判断是否可就读
                                if (BoolEnum.TRUE.getType().equals(schoolDistrictVO.getHouseholdEndTimeNo())) {
                                    schoolDistrictVO.setAttendFlag(true);
                                } else {
                                    schoolDistrictVO.setAttendFlag(attendFlag);
                                }
                            }
                            item.setSchoolDistrictVOList(schoolDistrictVOList);
                        }
                    }
                    canEnrollFlag = true;

                } else {
                    //没有户籍的，判断是否有房产
                    AreaControlVO areaControlVO = new AreaControlVO();
                    areaControlVO.setAreaCode(baseVO.getAreaCode());
                    List<EduHouseVO> houseVOS = eduHouseIntegration.getMyHouseInfo(areaControlVO);
                    if (!CollectionUtils.isEmpty(houseVOS)) {
                        canEnrollFlag = true;
                    }
                    if (!canEnrollFlag) {
                        //社保
                        List<EduSocialSecurityVO> list = eduSocialSecurityIntegration.getAppSocialSecurityList(areaControlVO);
                        if (!CollectionUtils.isEmpty(list)) {
                            for (EduSocialSecurityVO eduSocialSecurityVO : list) {
                                if ("1".equalsIgnoreCase(eduSocialSecurityVO.getStatus()) && "1".equalsIgnoreCase(eduSocialSecurityVO.getContinuityFlag())) {
                                    canEnrollFlag = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!canEnrollFlag) {
                        //居住证
                        List<EduLivePlaceVO> list = eduLivePlaceIntegration.getAppLivePlaceList(areaControlVO);
                        if (!CollectionUtils.isEmpty(list)) {
                            for (EduLivePlaceVO eduLivePlaceVO : list) {
                                if ("2".equalsIgnoreCase(eduLivePlaceVO.getZjztdm()) && !eduLivePlaceVO.getExpireFlag()) {
                                    canEnrollFlag = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!canEnrollFlag) {
                        //网签
                        List<EduNetsignVO> list = eduNetsignIntegration.getAppNetsignList(areaControlVO);
                        if (!CollectionUtils.isEmpty(list)) {
                            canEnrollFlag = true;
                        }
                    }

                }
                if (!canEnrollFlag) {
                    //判断是否直升班
                    QueryWrapper<EduPrivateAppointStudent> queryWrapper = new QueryWrapper<>();
                    queryWrapper.lambda().eq(EduPrivateAppointStudent::getYear, item.getYear())
                            .eq(EduPrivateAppointStudent::getIdcard, item.getIdcard())
                            .eq(EduPrivateAppointStudent::getStatus, BoolEnum.TRUE.getType());
                    if (eduPrivateAppointStudentService.count(queryWrapper) > 0) {
                        canEnrollFlag = true;
                    }

                }
                item.setCanEnrollFlag(canEnrollFlag);
                if("1".equalsIgnoreCase(mnFlagStr)||"true".equalsIgnoreCase(mnFlagStr)){
                    //模拟报名情况
                    QueryWrapper<EduStudentEnrollImitate> imitateQueryWrapper = new QueryWrapper<>();
                    imitateQueryWrapper.lambda().eq(EduStudentEnrollImitate::getIdcard, item.getIdcard())
                            .eq(EduStudentEnrollImitate::getYear, item.getYear())
                            .in(EduStudentEnrollImitate::getEnrollStatus, enrollStatusList);
                    if (eduStudentEnrollImitateService.count(imitateQueryWrapper) <= 0) {
                        item.setMnEnrollFlag(false);
                    } else {
                        item.setMnEnrollFlag(true);
                    }
                }
                //报名情况
                QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
                enrollQueryWrapper.lambda().eq(EduStudentEnroll::getIdcard, item.getIdcard())
                        .eq(EduStudentEnroll::getYear, item.getYear())
                        .in(EduStudentEnroll::getEnrollStatus, enrollStatusList);
                if (eduStudentEnrollService.count(enrollQueryWrapper) <= 0) {
                    item.setBmFlag(false);
                } else {
                    item.setBmFlag(true);
                }

                if (!ObjectUtils.isEmpty(item.getBusNo()) && StringUtils.isBlank(item.getFileInfo())) {
                    QueryWrapper<BusiFile> busiFileQueryWrapper = new QueryWrapper<>();
                    busiFileQueryWrapper
                            .lambda()
                            .eq(BusiFile::getBusNo, item.getBusNo().longValue());
                    List<BusiFile> busiFiles = busiFileService.list(busiFileQueryWrapper);
                    if (!CollectionUtils.isEmpty(busiFiles)) {
                        String fileInfo = busiFiles.stream().map(BusiFile::getFileOrigUrl).collect(Collectors.joining(","));
                        item.setFileInfo(fileInfo);
                    }
                }
                //获取修改审核情况
                QueryWrapper<EduBusiEnrollPre> xgEnrollPreQueryWrapper = new QueryWrapper<>();
                xgEnrollPreQueryWrapper.lambda().eq(EduBusiEnrollPre::getIdcard, item.getIdcard())
                        .eq(EduBusiEnrollPre::getYear, year)
                        .eq(EduBusiEnrollPre::getType, SaveTypeEnum.UPDATE.getType())
                        .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NODO.getType())
                        .orderByDesc(EduBusiEnrollPre::getCreateTime)
                        .last("limit 1");
                List<EduBusiEnrollPre> xgEnrollPreList = eduBusiEnrollPreService.list(xgEnrollPreQueryWrapper);
                if (!CollectionUtils.isEmpty(xgEnrollPreList)) {
                    EduBusiEnrollPre eduBusiEnrollPre = xgEnrollPreList.get(0);
                    BeanUtil.copyProperties(eduBusiEnrollPre, item);
                }
                dictHelper.valueToName(item, Arrays.asList(EduEnrollPreDictEnum.values()));
                resList.add(item);
            }
        }


        // 获取新增未审核数据
        QueryWrapper<EduBusiEnrollPre> busiEnrollPreQueryWrapper = new QueryWrapper<>();
        busiEnrollPreQueryWrapper.lambda().and(
                        wrapper -> {
                            wrapper.eq(EduBusiEnrollPre::getSubmitterId, userId)
                                    .or()
                                    .eq(EduBusiEnrollPre::getFatherIdcard, idcard)
                                    .or()
                                    .eq(EduBusiEnrollPre::getIdcard, idcard)
                                    .or()
                                    .eq(EduBusiEnrollPre::getMotherIdcard, idcard);
                        })
                .eq(EduBusiEnrollPre::getYear, year)
                .eq(EduBusiEnrollPre::getType, SaveTypeEnum.INSERT.getType())
                .notIn(!CollectionUtils.isEmpty(notidcardList), EduBusiEnrollPre::getIdcard, notidcardList)
                .ne(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .orderByDesc(EduBusiEnrollPre::getIdcard, EduBusiEnrollPre::getCreateTime);

        List<EduBusiEnrollPre> busiEnrollPreList2 = eduBusiEnrollPreService.list(busiEnrollPreQueryWrapper);

        List<EduBusiEnrollPreVO> busiEnrollPreList = Convert.toList(EduBusiEnrollPreVO.class, busiEnrollPreList2);
        dictHelper.valueToName(busiEnrollPreList, Arrays.asList(SchoolDictEnum.values()));
        List<EduStudentEnrollPreVO> list = new ArrayList<>();
        if (!CollectionUtils.isEmpty(busiEnrollPreList)) {
            Map<String, String> map = new HashMap<>();
            for (EduBusiEnrollPreVO eduBusiEnrollPre : busiEnrollPreList) {
                if (map.containsKey(eduBusiEnrollPre.getIdcard())) {
                    continue;
                } else {
                    map.put(eduBusiEnrollPre.getIdcard(), eduBusiEnrollPre.getFullName());
                    EduStudentEnrollPreVO eduStudentEnrollPreVO = Convert.convert(EduStudentEnrollPreVO.class, eduBusiEnrollPre);
                    String schoolId = eduStudentEnrollPreVO.getSchoolId();
                    if (StringUtils.isNotBlank(schoolId)) {
                        EduSchoolVO eduSchool = eduSchoolService.getDetail(schoolId);
                        eduStudentEnrollPreVO.setSchoolName(eduSchool.getSchoolName());
                    }
                    list.add(eduStudentEnrollPreVO);
                }
            }


        }
        if (!CollectionUtils.isEmpty(resList)) {
            list.addAll(resList);
        }
        cache.put(key, list);
        return list;
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpreJh0015", title = "金华家长端获取我的当年适龄子女", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public List<EduStudentEnrollPreVO> getMyChildsJh(AreaControlVO baseVO) {
        String userId = SessionUtil.getUserId();
        String idcard = SessionUtil.getSessionInfo() == null ? null : SessionUtil.getSessionInfo().getIdcard();
        if (StringUtils.isBlank(idcard)) {
            throw new AppException("用户的证件号码不能为空");
        }
        String key = idcard;
        Cache<String, List<EduStudentEnrollPreVO>> cache = JetCacheUtils.create(EduCache.EDU_MY_ENROLL_PRE, CacheType.BOTH, Duration.ofHours(6), Duration.ofSeconds(20));
        List<EduStudentEnrollPreVO> value = cache.get(key);
        if (value != null) {
            return value;
        }
        List<String> areaCodeList=new ArrayList<>();
        if (StringUtils.isBlank(baseVO.getAreaCode())) {
            //获取当前部署行政区划
            String areaCode = eduHelper.thisAreaCode();
            if (StringUtils.isBlank(areaCode)) {
                throw new AppException("系统参数中当前部署行政区划不能为空");
            }
            baseVO.setAreaCode(areaCode);
            DictAreaVO dictAreaVO = new DictAreaVO();
            dictAreaVO.setPermissionFlag(false);
            List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
            if(!CollectionUtils.isEmpty(districtByOrg)){
                areaCodeList=districtByOrg.stream().map(SelectVO::getDictKey).distinct().collect(Collectors.toList());
            }else{
                areaCodeList.add(areaCode);
            }
        }else{
            areaCodeList.add(baseVO.getAreaCode());
        }
        CommonVO commonTestVO=new CommonVO();
        commonTestVO.setParamKey("imitate_flag");
        String mnFlagStr=commonIntegration.getValueByKey(commonTestVO);

        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setOperating("YW025");
        queryVO.setAreaCode(baseVO.getAreaCode());
        queryVO.setClassify("2");
        EduOperationCacheDetailVO hjOption = eduSystemConfigIntegration.getEduOperationOne(queryVO);
        int year = hjOption.getYear();
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        //已采集数据
        studentEnrollPreQueryWrapper
                .lambda()
                .eq(EduStudentEnrollPre::getYear, year)
                .and(
                        wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getSubmitterId, userId)
                                    .or()
                                    .eq(EduStudentEnrollPre::getFatherIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getIdcard, idcard)
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, idcard);
                        }).orderByAsc(EduStudentEnrollPre::getIdcard);
        List<EduStudentEnrollPre> queryList =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        List<String> notidcardList = new ArrayList<>();
        List<EduStudentEnrollPreVO> resList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(queryList)) {
            Long householdEndTime = null;
            if (hjOption != null && hjOption.getEndTime() != null) {
                householdEndTime = hjOption.getEndTime().getTime() / 1000;
            }
            //获取报名情况
            List<String> enrollStatusList = new ArrayList<>();
            enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
            final Long endTime = householdEndTime;


            for (EduStudentEnrollPre pre : queryList) {
                EduStudentEnrollPreVO item = Convert.convert(EduStudentEnrollPreVO.class, pre);
                String schoolId = item.getSchoolId();
                if (StringUtils.isNotBlank(schoolId)) {
                    EduSchoolVO eduSchool = eduSchoolService.getDetail(schoolId);
                    item.setSchoolName(eduSchool.getSchoolName());
                }
                if (StringUtils.isBlank(item.getCardType())) {
                    item.setCardType(CardTypeEnum.idcard.getType());
                }
                if (StringUtils.isBlank(item.getFatherCardType())) {
                    item.setFatherCardType(CardTypeEnum.idcard.getType());
                }
                if (StringUtils.isBlank(item.getMotherCardType())) {
                    item.setMotherCardType(CardTypeEnum.idcard.getType());
                }
                notidcardList.add(item.getIdcard());
                QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                householdQueryWrapper
                        .lambda()
                        .eq(EduHousehold::getIdcard, item.getIdcard())
                        .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                        .eq(EduHousehold::getYear, year)
                        .orderByDesc(EduHousehold::getQysj)
                        .last("limit 1");
                EduHousehold household = eduHouseholdService.getOne(householdQueryWrapper);
                boolean canEnrollFlag = false;
                if (!ObjectUtils.isEmpty(household)) {
                    QueryWrapper<EduComplaint> queryWrapper = new QueryWrapper<>();
                    queryWrapper.lambda().select(EduComplaint::getHandleStatus, EduComplaint::getOtherId).eq(EduComplaint::getType, ComplaintTypeEnum.hjxq.getType())
                            .eq(EduComplaint::getHandleStatus, BoolEnum.FALSE.getType())
                            .eq(EduComplaint::getOtherId, household.getHouseholdId());
                    List<EduComplaint> complaints = eduComplaintService.list(queryWrapper);
                    if (!CollectionUtils.isEmpty(complaints)) {
                        item.setHouseholdHandleStatus(complaints.get(0).getHandleStatus());
                    }
                    item.setHouseholdId(household.getHouseholdId());
                    item.setStreet(household.getStreet());
                    if (StringUtils.isBlank(item.getHouseholdPlace())) {
                        item.setHouseholdPlace(household.getAddress());
                    }
                    item.setRelation(household.getRelation());
                    item.setAccountType(household.getAccountType());
                    item.setHouseholdAddress(household.getAddress());
                    item.setHouseholdTime(household.getUpdateTime());
                    if (endTime != null && StringUtils.isNotBlank(household.getAddressId())) {
                        Boolean attendFlag = true;
                        if (endTime != null && household.getQysj() != null) {
                            Long qysj = DateUtil.parse(household.getQysj()).getTime() / 1000;
                            if (qysj > endTime) {
                                attendFlag = false;
                            }
                        }
                        SchoolDistrictQueryVO xqQuery = new SchoolDistrictQueryVO();
                        xqQuery.setAddressId(household.getAddressId());
                        xqQuery.setSchoolCategory(item.getSchoolCategory());
                        List<SchoolDistrictVO> schoolDistrictVOList = eduAddressSchoolService.getSchoolInfo(xqQuery);
                        if (!CollectionUtils.isEmpty(schoolDistrictVOList)) {
                            dictHelper.valueToName(schoolDistrictVOList, Arrays.asList(SchoolDictEnum.values()));
                            for (SchoolDistrictVO schoolDistrictVO : schoolDistrictVOList) {
                                if (item.getSchoolCategory().equals(schoolDistrictVO.getSchoolCategory())) {
                                    schoolDistrictVO.setAgeFlag(true);
                                } else {
                                    schoolDistrictVO.setAgeFlag(false);
                                }
                                //判断是否可就读
                                if (BoolEnum.TRUE.getType().equals(schoolDistrictVO.getHouseholdEndTimeNo())) {
                                    schoolDistrictVO.setAttendFlag(true);
                                } else {
                                    schoolDistrictVO.setAttendFlag(attendFlag);
                                }
                            }
                            item.setSchoolDistrictVOList(schoolDistrictVOList);
                        }
                    }
                    canEnrollFlag = true;

                }

                if("1".equalsIgnoreCase(mnFlagStr)||"true".equalsIgnoreCase(mnFlagStr)){
                    //模拟报名情况
                    QueryWrapper<EduStudentEnrollImitate> imitateQueryWrapper = new QueryWrapper<>();
                    imitateQueryWrapper.lambda().eq(EduStudentEnrollImitate::getIdcard, item.getIdcard())
                            .eq(EduStudentEnrollImitate::getYear, item.getYear())
                            .in(EduStudentEnrollImitate::getEnrollStatus, enrollStatusList);
                    if (eduStudentEnrollImitateService.count(imitateQueryWrapper) <= 0) {
                        item.setMnEnrollFlag(false);
                    } else {
                        item.setMnEnrollFlag(true);
                    }
                }
                //报名情况
                QueryWrapper<EduStudentEnroll> enrollQueryWrapper = new QueryWrapper<>();
                enrollQueryWrapper.lambda().eq(EduStudentEnroll::getIdcard, item.getIdcard())
                        .eq(EduStudentEnroll::getYear, item.getYear())
                        .in(EduStudentEnroll::getEnrollStatus, enrollStatusList);
                if (eduStudentEnrollService.count(enrollQueryWrapper) <= 0) {
                    item.setBmFlag(false);
                } else {
                    item.setBmFlag(true);
                }

                if (!ObjectUtils.isEmpty(item.getBusNo()) && StringUtils.isBlank(item.getFileInfo())) {
                    QueryWrapper<BusiFile> busiFileQueryWrapper = new QueryWrapper<>();
                    busiFileQueryWrapper
                            .lambda()
                            .eq(BusiFile::getBusNo, item.getBusNo().longValue());
                    List<BusiFile> busiFiles = busiFileService.list(busiFileQueryWrapper);
                    if (!CollectionUtils.isEmpty(busiFiles)) {
                        String fileInfo = busiFiles.stream().map(BusiFile::getFileOrigUrl).collect(Collectors.joining(","));
                        item.setFileInfo(fileInfo);
                    }
                }
                //获取修改审核情况
                QueryWrapper<EduBusiEnrollPre> xgEnrollPreQueryWrapper = new QueryWrapper<>();
                xgEnrollPreQueryWrapper.lambda().eq(EduBusiEnrollPre::getIdcard, item.getIdcard())
                        .eq(EduBusiEnrollPre::getYear, year)
                        .eq(EduBusiEnrollPre::getType, SaveTypeEnum.UPDATE.getType())
                        .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NODO.getType())
                        .orderByDesc(EduBusiEnrollPre::getCreateTime)
                        .last("limit 1");
                List<EduBusiEnrollPre> xgEnrollPreList = eduBusiEnrollPreService.list(xgEnrollPreQueryWrapper);
                if (!CollectionUtils.isEmpty(xgEnrollPreList)) {
                    EduBusiEnrollPre eduBusiEnrollPre = xgEnrollPreList.get(0);
                    BeanUtil.copyProperties(eduBusiEnrollPre, item);
                }
                dictHelper.valueToName(item, Arrays.asList(EduEnrollPreDictEnum.values()));
                resList.add(item);
            }
        }


        // 获取新增未审核数据
        QueryWrapper<EduBusiEnrollPre> busiEnrollPreQueryWrapper = new QueryWrapper<>();
        busiEnrollPreQueryWrapper.lambda().and(
                wrapper -> {
                    wrapper.eq(EduBusiEnrollPre::getSubmitterId, userId)
                            .or()
                            .eq(EduBusiEnrollPre::getFatherIdcard, idcard)
                            .or()
                            .eq(EduBusiEnrollPre::getIdcard, idcard)
                            .or()
                            .eq(EduBusiEnrollPre::getMotherIdcard, idcard);
                })
                .eq(EduBusiEnrollPre::getYear, year)
                .eq(EduBusiEnrollPre::getType, SaveTypeEnum.INSERT.getType())
                .notIn(!CollectionUtils.isEmpty(notidcardList), EduBusiEnrollPre::getIdcard, notidcardList)
                .ne(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .orderByDesc(EduBusiEnrollPre::getIdcard, EduBusiEnrollPre::getCreateTime);

        List<EduBusiEnrollPre> busiEnrollPreList2 = eduBusiEnrollPreService.list(busiEnrollPreQueryWrapper);

        List<EduBusiEnrollPreVO> busiEnrollPreList = Convert.toList(EduBusiEnrollPreVO.class, busiEnrollPreList2);
        dictHelper.valueToName(busiEnrollPreList, Arrays.asList(SchoolDictEnum.values()));
        List<EduStudentEnrollPreVO> list = new ArrayList<>();
        if (!CollectionUtils.isEmpty(busiEnrollPreList)) {
            Map<String, String> map = new HashMap<>();
            for (EduBusiEnrollPreVO eduBusiEnrollPre : busiEnrollPreList) {
                if (map.containsKey(eduBusiEnrollPre.getIdcard())) {
                    continue;
                } else {
                    map.put(eduBusiEnrollPre.getIdcard(), eduBusiEnrollPre.getFullName());
                    EduStudentEnrollPreVO eduStudentEnrollPreVO = Convert.convert(EduStudentEnrollPreVO.class, eduBusiEnrollPre);
                    String schoolId = eduStudentEnrollPreVO.getSchoolId();
                    if (StringUtils.isNotBlank(schoolId)) {
                        EduSchoolVO eduSchool = eduSchoolService.getDetail(schoolId);
                        eduStudentEnrollPreVO.setSchoolName(eduSchool.getSchoolName());
                    }
                    list.add(eduStudentEnrollPreVO);
                }
            }


        }
        if (!CollectionUtils.isEmpty(resList)) {
            list.addAll(resList);
        }
        cache.put(key, list);
        return list;
    }
    @Override
    @OpApi(funcCode = "edustudentenrollpre0016", title = "家长端当年适龄子女控制信息获取", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public MyChildCheckVO getMyChildCheckVO(AreaControlVO baseVO) {
        String idcard = SessionUtil.getSessionInfo().getIdcard();
        if (StringUtils.isNotBlank(idcard)){
            LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper =
                    new QueryWrapper<EduStudentEnrollPre>().lambda()
                            .eq(EduStudentEnrollPre::getYear,eduHelper.thisYear())
                            .eq(EduStudentEnrollPre::getAuthStatus,AuthStatusEnum.YES.getType())
                            .eq(EduStudentEnrollPre::getFatherIdcard, idcard).or().eq(EduStudentEnrollPre::getMotherIdcard, idcard);
            EduStudentEnrollPre eduStudentEnrollPre = eduStudentEnrollPreService.getOne(queryWrapper, false);
            if(eduStudentEnrollPre!=null){
                baseVO.setAreaCode(eduStudentEnrollPre.getAreaCode());
            }
        }
        if (StringUtils.isBlank(baseVO.getAreaCode())) {
            //获取当前部署行政区划
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode = commonIntegration.getValueByKey(commonVO);
            if (StringUtils.isBlank(areaCode)) {
                throw new AppException("系统参数中当前部署行政区划不能为空");
            }
            baseVO.setAreaCode(areaCode);
        }
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(baseVO.getAreaCode());
        EduOperationCacheVO operationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        Map<String, EduOperationCacheDetailVO> operation = operationCacheVO.getOperation();
        MyChildCheckVO myChildCheckVO = new MyChildCheckVO();
        //判断是否报名时间开始
        EduOperationCacheDetailVO otherInfoVO = operation.get("YW053");
        if (otherInfoVO != null && otherInfoVO.isFlag()) {
            myChildCheckVO.setShowOtherInfo(true);
        } else {
            myChildCheckVO.setShowOtherInfo(false);
        }
        EduOperationCacheDetailVO mnOperation = operation.get("YW062");//模拟报名
        if (mnOperation != null && mnOperation.isFlag()) {
            myChildCheckVO.setMnFlag(true);
        } else {
            myChildCheckVO.setMnFlag(false);
        }
        //判断是否报名时间开始
        EduOperationCacheDetailVO bmVO = operation.get("YW002");
        myChildCheckVO.setOneFlag(false);
        myChildCheckVO.setTwoFlag(false);
        myChildCheckVO.setThreeFlag(false);
        if (bmVO != null && (bmVO.isFlag() || "2".equalsIgnoreCase(bmVO.getType()))) {
            myChildCheckVO.setBmFlag(true);
            if(bmVO.isFlag()){
                myChildCheckVO.setOneFlag(true);
            }
        } else {
            myChildCheckVO.setBmFlag(false);
        }
        EduOperationCacheDetailVO bbVO = operation.get("YW022");
        if (bbVO != null && bbVO.isFlag()) {
            myChildCheckVO.setTwoFlag(true);
        } else {
            myChildCheckVO.setTwoFlag(false);
        }
        EduOperationCacheDetailVO bbTwoVO = operation.get("YW072");
        if (bbTwoVO != null && bbTwoVO.isFlag()) {
            myChildCheckVO.setTwoTwoFlag(true);
        } else {
            myChildCheckVO.setTwoTwoFlag(false);
        }
        EduOperationCacheDetailVO qbVO = operation.get("YW010");
        if (qbVO != null && qbVO.isFlag()) {
            myChildCheckVO.setThreeFlag(true);
        } else {
            myChildCheckVO.setThreeFlag(false);
        }
        //基础信息修改
        EduOperationCacheDetailVO baseEditVO = operation.get("YW019");
        if (baseEditVO != null && baseEditVO.isFlag()) {
            myChildCheckVO.setEditBaseFlag(true);
        } else {
            myChildCheckVO.setEditBaseFlag(false);
        }
        boolean canEnrollFlag = true;
        //户籍
        CheckItemVO hjVO = new CheckItemVO();
        //户籍基本信息显示
        EduOperationCacheDetailVO showHj = operation.get("YW029");
        if (showHj != null && showHj.isFlag()) {
            hjVO.setShowBaseFlag(true);
        } else {
            hjVO.setShowBaseFlag(false);
            canEnrollFlag = false;
        }
        //户籍学区信息显示
        EduOperationCacheDetailVO showHjXq = operation.get("YW030");
        if (showHjXq != null && showHjXq.isFlag()) {
            hjVO.setShowXqFlag(true);
        } else {
            hjVO.setShowXqFlag(false);
        }
        //户籍基础信息申诉
        EduOperationCacheDetailVO hjss = operation.get("YW031");
        if (hjss != null && hjss.isFlag()) {
            hjVO.setSsBaseFlag(true);
        } else {
            hjVO.setSsBaseFlag(false);
        }
        //户籍基础学区申诉
        EduOperationCacheDetailVO hjxqss = operation.get("YW032");
        if (hjxqss != null && hjxqss.isFlag()) {
            hjVO.setSsXqFlag(true);
        } else {
            hjVO.setSsXqFlag(false);
        }
        //户籍大数据获取
        EduOperationCacheDetailVO hjdsj = operation.get("YW033");
        if (hjdsj != null && hjdsj.isFlag()) {
            hjVO.setDsjFlag(true);
        } else {
            hjVO.setDsjFlag(false);
        }
        myChildCheckVO.setHjCheck(hjVO);
        //房产
        CheckItemVO fcVO = new CheckItemVO();
        //房产基本信息显示
        EduOperationCacheDetailVO showFc = operation.get("YW034");
        if (showFc != null && showFc.isFlag()) {
            fcVO.setShowBaseFlag(true);
        } else {
            fcVO.setShowBaseFlag(false);
            canEnrollFlag = false;
        }
        //户房产学区信息显示
        EduOperationCacheDetailVO showFcXq = operation.get("YW035");
        if (showFcXq != null && showFcXq.isFlag()) {
            fcVO.setShowXqFlag(true);
        } else {
            fcVO.setShowXqFlag(false);
        }
        //房产基础信息申诉
        EduOperationCacheDetailVO fcss = operation.get("YW036");
        if (fcss != null && fcss.isFlag()) {
            fcVO.setSsBaseFlag(true);
        } else {
            fcVO.setSsBaseFlag(false);
        }
        //房产学区申诉
        EduOperationCacheDetailVO fcxqss = operation.get("YW037");
        if (fcxqss != null && fcxqss.isFlag()) {
            fcVO.setSsXqFlag(true);
        } else {
            fcVO.setSsXqFlag(false);
        }
        //房产大数据获取
        EduOperationCacheDetailVO fcdsj = operation.get("YW038");
        if (fcdsj != null && fcdsj.isFlag()) {
            fcVO.setDsjFlag(true);
        } else {
            fcVO.setDsjFlag(false);
        }
        myChildCheckVO.setFcCheck(fcVO);
        //居住证
        CheckItemVO jjzVO = new CheckItemVO();
        //居住证基础信息显示
        EduOperationCacheDetailVO showJzz = operation.get("YW039");
        if (showJzz != null && showJzz.isFlag()) {
            jjzVO.setShowBaseFlag(true);
        } else {
            jjzVO.setShowBaseFlag(false);
            canEnrollFlag = false;
        }
        //居住证基础信息申诉
        EduOperationCacheDetailVO jjzss = operation.get("YW040");
        if (jjzss != null && jjzss.isFlag()) {
            jjzVO.setSsBaseFlag(true);
        } else {
            jjzVO.setSsBaseFlag(false);
        }
        //居住证大数据获取
        EduOperationCacheDetailVO jjzdsj = operation.get("YW041");
        if (jjzdsj != null && jjzdsj.isFlag()) {
            jjzVO.setDsjFlag(true);
        } else {
            jjzVO.setDsjFlag(false);
        }
        myChildCheckVO.setJzzCheck(jjzVO);
        //社保
        CheckItemVO sbVO = new CheckItemVO();
        //社保基础信息显示
        EduOperationCacheDetailVO showsb = operation.get("YW042");
        if (showsb != null && showsb.isFlag()) {
            sbVO.setShowBaseFlag(true);
        } else {
            sbVO.setShowBaseFlag(false);
            canEnrollFlag = false;
        }
        //社保基础信息申诉
        EduOperationCacheDetailVO sbss = operation.get("YW043");
        if (sbss != null && sbss.isFlag()) {
            sbVO.setSsBaseFlag(true);
        } else {
            sbVO.setSsBaseFlag(false);
        }
        //社保大数据获取
        EduOperationCacheDetailVO sbdsj = operation.get("YW044");
        if (sbdsj != null && sbdsj.isFlag()) {
            sbVO.setDsjFlag(true);
        } else {
            sbVO.setDsjFlag(false);
        }
        myChildCheckVO.setSbCheck(sbVO);
        //企业
        CheckItemVO qyVO = new CheckItemVO();
        //企业基础信息显示
        EduOperationCacheDetailVO showqy = operation.get("YW045");
        if (showqy != null && showqy.isFlag()) {
            qyVO.setShowBaseFlag(true);
        } else {
            qyVO.setShowBaseFlag(false);
        }
        //企业基础信息申诉
        EduOperationCacheDetailVO qyss = operation.get("YW046");
        if (qyss != null && qyss.isFlag()) {
            qyVO.setSsBaseFlag(true);
        } else {
            qyVO.setSsBaseFlag(false);
        }
        //企业大数据获取
        EduOperationCacheDetailVO qydsj = operation.get("YW047");
        if (qydsj != null && qydsj.isFlag()) {
            qyVO.setDsjFlag(true);
        } else {
            qyVO.setDsjFlag(false);
        }
        myChildCheckVO.setQyCheck(qyVO);
        //网签
        CheckItemVO wqVO = new CheckItemVO();
        //网签基础信息显示
        EduOperationCacheDetailVO showwq = operation.get("YW048");
        if (showwq != null && showwq.isFlag()) {
            wqVO.setShowBaseFlag(true);
        } else {
            wqVO.setShowBaseFlag(false);
            canEnrollFlag = false;
        }
        //网签基础信息申诉
        EduOperationCacheDetailVO wqss = operation.get("YW049");
        if (wqss != null && wqss.isFlag()) {
            wqVO.setSsBaseFlag(true);
        } else {
            wqVO.setSsBaseFlag(false);
        }
        //网签大数据获取
        EduOperationCacheDetailVO wqdsj = operation.get("YW050");
        if (wqdsj != null && wqdsj.isFlag()) {
            wqVO.setDsjFlag(true);
        } else {
            wqVO.setDsjFlag(false);
        }
        myChildCheckVO.setWqCheck(wqVO);
        myChildCheckVO.setCanEnrollFlag(canEnrollFlag);
        return myChildCheckVO;
    }

    private void setData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EduStudentEnrollPreQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            PageInfo<EduStudentEnrollPreVO> pageInfo = getList(vo);
            String total = String.valueOf(pageInfo.getTotal());
            List<Map<String, Object>> list = new ArrayList<>();
            if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                for (EduStudentEnrollPreVO studentEnrollPreVO : pageInfo.getList()) {
                    list.add(BeanUtil.beanToMap(studentEnrollPreVO, false, true));
                }
            }
            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (pageInfo.isHasNextPage()) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    private List<SelectVO> getSchoolDictMap() {
        HashMap<String, Object> map = new HashMap<>();

        EduSchoolVO lreduSchool = eduSchoolService.getDetail(SessionUtil.getSessionInfo().getOrgId());
        if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(lreduSchool)) {
            if (lreduSchool.getSchoolCategory().equals(SchoolCategoryEnum.KINDERGARTEN.getType())) {
                map.put("schoolCategory", SchoolCategoryEnum.PRIMARY.getType());
            }
            if (lreduSchool.getSchoolCategory().equals(SchoolCategoryEnum.PRIMARY.getType())) {
                map.put("schoolCategory", SchoolCategoryEnum.JUNIOR.getType());
            }
        }
        map.put("schoolNature", "0");
        map.put("recruitStatus", "0");
        map.put("preFlag", "1");

        List<EduSchoolVO> schoolList = eduSchoolService.selectSchoolList(map);
        List<SelectVO> schoolDictList = new ArrayList<>();
        schoolList.forEach(
                item -> {
                    SelectVO selectVO = new SelectVO();
                    selectVO.setDictKey(item.getOrgId());
                    selectVO.setDictValue(item.getShortName());
                    selectVO.setDictField("schoolName");
                    selectVO.setFieldName("学校");
                    schoolDictList.add(selectVO);
                });
        return schoolDictList;
    }


    public ExcelModelVO getModel(ExcelVO vo) {
        return this.getModel(vo.getModelCode(), vo.getExcelVersion(), vo.getDictMap());
    }

    public ExcelModelVO getModel(
            String modelCode, String version, Map<String, List<SelectVO>> dictMap) {
        if (StringUtils.isBlank(modelCode)) {
            throw new AppException("模板编号不能为空");
        }
        QueryWrapper<ExcelModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ExcelModel::getModelCode, modelCode);
        if (StringUtils.isBlank(version)) {
            queryWrapper.lambda().eq(ExcelModel::getNewFlag, BoolEnum.TRUE.getType());
        } else {
            queryWrapper.lambda().eq(ExcelModel::getExcelVersion, version);
        }
        ExcelModel excelModel = excelModelService.getOne(queryWrapper, false);
        if (excelModel == null) {
            throw new AppException("未找到excel模板信息");
        }
        ExcelModelVO excelModelVO = Convert.convert(ExcelModelVO.class, excelModel);
        // 获取字段信息
        List<ExcelParamVO> paramVOList = this.getByModelId(excelModelVO.getId());
        for (ExcelParamVO excelParamVO : paramVOList) {
            if (excelParamVO.getHeaderBgColor() == null) {
                excelParamVO.setHeaderBgColor(excelModelVO.getHeaderBgColor());
            }
            if (excelParamVO.getHeaderColor() == null) {
                excelParamVO.setHeaderColor(excelModelVO.getHeaderColor());
            }
            if (excelParamVO.getBodyBgColor() == null) {
                excelParamVO.setBodyBgColor(excelModelVO.getBodyBgColor());
            }
            if (excelParamVO.getBodyColor() == null) {
                excelParamVO.setBodyColor(excelModelVO.getBodyColor());
            }
            if (StringUtils.isBlank(excelParamVO.getWrapText())) {
                excelParamVO.setWrapText(excelModelVO.getWrapText());
            }
            if (StringUtils.isBlank(excelParamVO.getFontName())) {
                excelParamVO.setFontName(excelModelVO.getFontName());
            }
            if (excelParamVO.getFontSize() == null) {
                excelParamVO.setFontSize(excelModelVO.getFontSize());
            }
            if (excelParamVO.getBorderSize() == null) {
                excelParamVO.setBorderSize(excelModelVO.getBorderSize());
            }
            if (excelParamVO.getBorderColor() == null) {
                excelParamVO.setBorderColor(excelModelVO.getBorderColor());
            }
            if (ExcelFieldVO.CellTypeEnum.SELECT.getType().equals(excelParamVO.getCellType())
                    || ExcelFieldVO.CellTypeEnum.MULTIPLESELECT
                    .getType()
                    .equals(excelParamVO.getCellType())) {
                String dictField = excelParamVO.getDictField();
                if (StringUtils.isBlank(dictField)) {
                    dictField = excelParamVO.getKey();
                }
                if (dictMap != null && dictMap.containsKey(dictField)) {
                    excelParamVO.setCodeList(dictMap.get(dictField));
                } else {
                    List<SelectVO> selectList = sysDictService.getDictByDictField(dictField);
                    excelParamVO.setCodeList(selectList);
                }
            }
        }
        excelModelVO.setParamVOList(paramVOList);
        if (StringUtils.isBlank(excelModelVO.getExcelType())) {
            excelModelVO.setExcelType(ExcelTypeEnum.xls.toString());
        }
        if (StringUtils.isBlank(excelModelVO.getExcelMode())) {
            excelModelVO.setExcelMode("2");
        }
        return excelModelVO;
    }

    public List<ExcelParamVO> getByModelId(String excelModelId) {
        QueryWrapper<ExcelParam> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .lambda()
                .eq(ExcelParam::getExcelModelId, excelModelId)
                .orderByAsc(ExcelParam::getOrderNo)
                .orderByAsc(ExcelParam::getCreateTime);
        List<ExcelParam> list = excelParamService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        List<ExcelParamVO> voList = Convert.toList(ExcelParamVO.class, list);
        return voList;
    }


    private PersonInfo savePerson(String idcard, String cardType, String fullName) {
        if (StringUtils.isBlank(cardType)) {
            cardType = CardTypeEnum.idcard.getType();
        }
        if(!CardTypeEnum.idcard.getType().equalsIgnoreCase(cardType)){
            if(IdcardUtil.isValidCard(idcard)&&idcard.length()>=15){
                cardType= CardTypeEnum.idcard.getType();
            }
        }
        PersonInfo personInfo =  personInfoService.selectByCardTypeAndIdcard(cardType, StringUtils.upperCase(idcard));
        if (personInfo == null) {
            QueryWrapper<PersonInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(PersonInfo::getIdcard, idcard);
            List<PersonInfo> list = personInfoService.list(queryWrapper);
            if (!CollectionUtils.isEmpty(list)) {
                personInfo = list.get(0);
            }
        }
        if (ObjectUtils.isEmpty(personInfo)) {
            personInfo = new PersonInfo();
            personInfo.setIdcard(StringUtils.upperCase(idcard));
            personInfo.setFullName(fullName);
            personInfo.setCardType(cardType);
            return personInfoService.addPerson(personInfo);
        } else {
            if (!personInfo.getFullName().equals(fullName)||!personInfo.getCardType().equals(cardType)) {
                personInfo.setIdcard(StringUtils.upperCase(idcard));
                personInfo.setFullName(fullName);
                personInfo.setCardType(cardType);
                personInfoService.updateById(personInfo);
            }
            return personInfo;
        }
    }

    private QueryWrapper<EduStudentEnrollPre> createQueryWrapper(EduStudentEnrollPreQueryVO vo) {
        QueryWrapper<EduStudentEnrollPre> enrollPreQueryWrapper = new QueryWrapper<>();
        enrollPreQueryWrapper
                .lambda()
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherIdcard()),
                        EduStudentEnrollPre::getFatherIdcard,
                        vo.getFatherIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherId()),
                        EduStudentEnrollPre::getFatherId,
                        vo.getFatherId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherName()),
                        EduStudentEnrollPre::getFatherName,
                        vo.getFatherName()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherCardType()),
                        EduStudentEnrollPre::getFatherCardType,
                        vo.getFatherCardType()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherIdcard()),
                        EduStudentEnrollPre::getMotherIdcard,
                        vo.getMotherIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherId()),
                        EduStudentEnrollPre::getMotherId,
                        vo.getMotherId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherName()),
                        EduStudentEnrollPre::getMotherName,
                        vo.getMotherName()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherCardType()),
                        EduStudentEnrollPre::getMotherCardType,
                        vo.getMotherCardType()
                )
                .eq(!ObjectUtils.isEmpty(vo.getMotherCellphone()),EduStudentEnrollPre::getMotherCellphone,vo.getMotherCellphone())
                .eq(!ObjectUtils.isEmpty(vo.getFatherCellphone()),EduStudentEnrollPre::getFatherCellphone,vo.getFatherCellphone())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSchoolId()),
                        EduStudentEnrollPre::getSchoolId,
                        vo.getSchoolId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getOrgId()),
                        EduStudentEnrollPre::getOrgId,
                        vo.getOrgId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getPersonId()),
                        EduStudentEnrollPre::getPersonId,
                        vo.getPersonId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getIdcard()),
                        EduStudentEnrollPre::getIdcard,
                        vo.getIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFullName()),
                        EduStudentEnrollPre::getFullName,
                        vo.getFullName())
                .eq(
                        !ObjectUtils.isEmpty(vo.getEnrollPreType()),
                        EduStudentEnrollPre::getEnrollPreType,
                        vo.getEnrollPreType())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSchoolCategory()),
                        EduStudentEnrollPre::getSchoolCategory,
                        vo.getSchoolCategory())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSaveType()),
                        EduStudentEnrollPre::getType,
                        vo.getSaveType())
                .eq(!ObjectUtils.isEmpty(vo.getYear()), EduStudentEnrollPre::getYear, vo.getYear())
                .eq(!ObjectUtils.isEmpty(vo.getAuthStatus()),
                        EduStudentEnrollPre::getAuthStatus,
                        vo.getAuthStatus());
        // 处理排序逻辑
        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    String column = StrUtil.toUnderlineCase(orderVO.getProperty()); // 转换为数据库字段格式
                    if ("asc".equalsIgnoreCase(orderVO.getOrder())) {
                        enrollPreQueryWrapper.orderByAsc(column);
                    } else if ("desc".equalsIgnoreCase(orderVO.getOrder())) {
                        enrollPreQueryWrapper.orderByDesc(column);
                    }
                }
            }
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())){
            List<String> areaCodeList
                    = dictIntegration.getDistrictByOrg(new DictAreaVO()).stream().map(SelectVO::getDictKey).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(areaCodeList)){
                enrollPreQueryWrapper.lambda().in(EduStudentEnrollPre::getAreaCode,areaCodeList);
            }else{
                throw new AppException("传入的行政区划不能为空");
            }
        }else{
            enrollPreQueryWrapper.lambda().eq(EduStudentEnrollPre::getAreaCode,vo.getAreaCode());
        }
        return enrollPreQueryWrapper;
    }

    /**
     * 加密后的QueryWrapper
     * @param vo
     * @return
     */
    private QueryWrapper<EduhStudentEnrollPre> createQueryWrapperHistory(EduStudentEnrollPreQueryVO vo) {
        QueryWrapper<EduhStudentEnrollPre> eduhStudentEnrollPreQueryWrapper = new QueryWrapper<>();
        eduhStudentEnrollPreQueryWrapper
                .lambda()
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherIdcard()),
                        EduhStudentEnrollPre::getFatherIdcard,
                        vo.getFatherIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherId()),
                        EduhStudentEnrollPre::getFatherId,
                        vo.getFatherId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherName()),
                        EduhStudentEnrollPre::getFatherName,
                        vo.getFatherName()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherCardType()),
                        EduhStudentEnrollPre::getFatherCardType,
                        vo.getFatherCardType()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherIdcard()),
                        EduhStudentEnrollPre::getMotherIdcard,
                        vo.getMotherIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherId()),
                        EduhStudentEnrollPre::getMotherId,
                        vo.getMotherId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherName()),
                        EduhStudentEnrollPre::getMotherName,
                        vo.getMotherName()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherCardType()),
                        EduhStudentEnrollPre::getMotherCardType,
                        vo.getMotherCardType()
                )
                .eq(!StringUtils.isEmpty(vo.getMotherCellphone()),EduhStudentEnrollPre::getMotherCellphone,vo.getMotherCellphone())
                .eq(!StringUtils.isEmpty(vo.getFatherCellphone()),EduhStudentEnrollPre::getFatherCellphone,vo.getFatherCellphone())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSchoolId()),
                        EduhStudentEnrollPre::getSchoolId,
                        vo.getSchoolId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getOrgId()),
                        EduhStudentEnrollPre::getOrgId,
                        vo.getOrgId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getPersonId()),
                        EduhStudentEnrollPre::getPersonId,
                        vo.getPersonId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getIdcard()),
                        EduhStudentEnrollPre::getIdcard,
                        vo.getIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFullName()),
                        EduhStudentEnrollPre::getFullName,
                        vo.getFullName())
                .eq(
                        !ObjectUtils.isEmpty(vo.getEnrollPreType()),
                        EduhStudentEnrollPre::getEnrollPreType,
                        vo.getEnrollPreType())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSchoolCategory()),
                        EduhStudentEnrollPre::getSchoolCategory,
                        vo.getSchoolCategory())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSaveType()),
                        EduhStudentEnrollPre::getType,
                        vo.getSaveType())
                .eq(!ObjectUtils.isEmpty(vo.getYear()), EduhStudentEnrollPre::getYear, vo.getYear())
                .eq(!ObjectUtils.isEmpty(vo.getAuthStatus()),
                        EduhStudentEnrollPre::getAuthStatus,
                        vo.getAuthStatus());

        // 处理排序逻辑
        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    String column = StrUtil.toUnderlineCase(orderVO.getProperty()); // 转换为数据库字段格式
                    if ("asc".equalsIgnoreCase(orderVO.getOrder())) {
                        eduhStudentEnrollPreQueryWrapper.orderByAsc(column);
                    } else if ("desc".equalsIgnoreCase(orderVO.getOrder())) {
                        eduhStudentEnrollPreQueryWrapper.orderByDesc(column);
                    }
                }
            }
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())){
            List<String> areaCodeList
                    = dictIntegration.getDistrictByOrg(new DictAreaVO()).stream().map(SelectVO::getDictKey).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(areaCodeList)){
                eduhStudentEnrollPreQueryWrapper.lambda().in(EduhStudentEnrollPre::getAreaCode,areaCodeList);
            }else{
                throw new AppException("传入的行政区划不能为空");
            }
        }else{
            eduhStudentEnrollPreQueryWrapper.lambda().eq(EduhStudentEnrollPre::getAreaCode,vo.getAreaCode());
        }
        return eduhStudentEnrollPreQueryWrapper;
    }

    private QueryWrapper<EduBusiEnrollPre> createBusiQueryWrapper(EduStudentEnrollPreQueryVO vo) {
        QueryWrapper<EduBusiEnrollPre> enrollPreQueryWrapper = new QueryWrapper<>();
        enrollPreQueryWrapper
                .lambda()
                .eq(
                        !ObjectUtils.isEmpty(vo.getSchoolId()),
                        EduBusiEnrollPre::getSchoolId,
                        vo.getSchoolId())
                .eq(!ObjectUtils.isEmpty(vo.getOrgId()), EduBusiEnrollPre::getOrgId, vo.getOrgId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getPersonId()),
                        EduBusiEnrollPre::getPersonId,
                        vo.getPersonId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getIdcard()),
                        EduBusiEnrollPre::getIdcard,
                        vo.getIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFullName()),
                        EduBusiEnrollPre::getFullName,
                        vo.getFullName())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherIdcard()),
                        EduBusiEnrollPre::getFatherIdcard,
                        vo.getFatherIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherCardType()),
                        EduBusiEnrollPre::getFatherCardType,
                        vo.getFatherCardType())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherId()),
                        EduBusiEnrollPre::getFatherId,
                        vo.getFatherId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getFatherName()),
                        EduBusiEnrollPre::getFatherName,
                        vo.getFatherName()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherIdcard()),
                        EduBusiEnrollPre::getMotherIdcard,
                        vo.getMotherIdcard())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherCardType()),
                        EduBusiEnrollPre::getMotherCardType,
                        vo.getMotherCardType())
                .eq(!ObjectUtils.isEmpty(vo.getMotherCellphone()),EduBusiEnrollPre::getMotherCellphone,vo.getMotherCellphone())
                .eq(!ObjectUtils.isEmpty(vo.getFatherCellphone()),EduBusiEnrollPre::getFatherCellphone,vo.getFatherCellphone())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherId()),
                        EduBusiEnrollPre::getMotherId,
                        vo.getMotherId())
                .eq(
                        !ObjectUtils.isEmpty(vo.getMotherName()),
                        EduBusiEnrollPre::getMotherName,
                        vo.getMotherName()
                )
                .eq(
                        !ObjectUtils.isEmpty(vo.getEnrollPreType()),
                        EduBusiEnrollPre::getEnrollPreType,
                        vo.getEnrollPreType())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSchoolCategory()),
                        EduBusiEnrollPre::getSchoolCategory,
                        vo.getSchoolCategory())
                .eq(
                        !ObjectUtils.isEmpty(vo.getSaveType()),
                        EduBusiEnrollPre::getType,
                        vo.getSaveType())
                .eq(
                        !ObjectUtils.isEmpty(vo.getAuthStatus()),
                        EduBusiEnrollPre::getAuthStatus,
                        vo.getAuthStatus())
                .eq(!ObjectUtils.isEmpty(vo.getYear()), EduBusiEnrollPre::getYear, vo.getYear());

        // 处理排序逻辑
        if (!CollectionUtils.isEmpty(vo.getOrderVOList())) {
            for (OrderVO orderVO : vo.getOrderVOList()) {
                if (StringUtils.isNotBlank(orderVO.getOrder()) && StringUtils.isNotBlank(orderVO.getProperty())) {
                    String column = StrUtil.toUnderlineCase(orderVO.getProperty()); // 转换为数据库字段格式
                    if ("asc".equalsIgnoreCase(orderVO.getOrder())) {
                        enrollPreQueryWrapper.orderByAsc(column);
                    } else if ("desc".equalsIgnoreCase(orderVO.getOrder())) {
                        enrollPreQueryWrapper.orderByDesc(column);
                    }
                }
            }
        }

        if (ObjectUtils.isEmpty(vo.getAreaCode())){
            List<String> areaCodeList
                    = dictIntegration.getDistrictByOrg(new DictAreaVO()).stream().map(SelectVO::getDictKey).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(areaCodeList)){
                enrollPreQueryWrapper.lambda().in(EduBusiEnrollPre::getAreaCode,areaCodeList);
            }else{
                throw new AppException("传入的行政区划不能为空");
            }
        }else{
            enrollPreQueryWrapper.lambda().eq(EduBusiEnrollPre::getAreaCode,vo.getAreaCode());
        }
        return enrollPreQueryWrapper;
    }

    private void checkBase(EduStudentEnrollPreVO vo) {
        if (StringUtils.isBlank(vo.getAreaCode())) {
            if (!EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                SessionInfo sessionInfo = SessionUtil.getSessionInfo();
                if (sessionInfo != null) {
                    vo.setAreaCode(sessionInfo.getAreaCode());
                    vo.setAreaName(sessionInfo.getAreaName());
                }
            } else {
                throw new AppException("家长端登记或修改行政区划不能为空");
            }
        }
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        //判断是否在经办业务期内
        if (EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            if (ObjectUtils.isEmpty(vo.getStudentEnrollPreId())) {
                eduSystemConfigIntegration.checkOperation(eduOperationCacheVO, "YW018");
            } else {
                eduSystemConfigIntegration.checkOperation(eduOperationCacheVO, "YW019");
            }

        } else if (EnrollPreTypeEnum.lr.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            eduSystemConfigIntegration.checkOperation(eduOperationCacheVO, "YW028");
        } else if (EnrollPreTypeEnum.ycj.getType().equals(vo.getEnrollPreType())) {
            eduSystemConfigIntegration.checkOperation(eduOperationCacheVO, "YW028");
        } else if (EnrollPreTypeEnum.tstd.getType().equals(vo.getEnrollPreType())) {
            eduSystemConfigIntegration.checkOperation(eduOperationCacheVO, "YW058");
        }

        if (StringUtils.isBlank(vo.getCardType())) {
            vo.setCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(vo.getIdcard())) {
            throw new AppException("学生证件号码不能为空");
        }
        vo.setIdcard(vo.getIdcard().trim().toUpperCase());
        if (CardTypeEnum.idcard.getType().equals(vo.getCardType()) && !IdcardUtil.isValidCard(vo.getIdcard())) {
            throw new AppException("学生身份证号码有误");
        }
        if (ObjectUtils.isEmpty(vo.getFullName())) {
            throw new AppException("学生姓名不能为空！");
        } else {
            vo.setFullName(
                    Validator.isChinese(vo.getFullName())
                            ? vo.getFullName().replaceAll(" ", "").replaceAll(" ", "").trim()
                            : vo.getFullName().trim());
        }
        if (!CardTypeEnum.idcard.getType().equals(vo.getCardType())) {
            if (StringUtils.isBlank(vo.getSex())) {
                throw new AppException("学生性别不能为空！");
            }
            if (StringUtils.isBlank(vo.getBirthYmd())) {
                throw new AppException("学生出生日期不能为空！");
            }
            String birthday = "";
            if (vo.getBirthYmd().length() >= 8) {
                birthday = vo.getBirthYmd().replaceAll("-", "").replaceAll("/", "");
            } else if (vo.getBirthYmd().length() == 6) {
                birthday = vo.getBirthYmd() + "01";
            } else {
                throw new AppException("学生出生日期格式不正确");
            }
            vo.setBirthYmd(birthday);
        } else {
            vo.setBirthYmd(IdcardUtil.getBirth(vo.getIdcard()));
            int gender = IdcardUtil.getGenderByIdCard(vo.getIdcard());
            if (gender == 1) {
                // 男
                vo.setSex("1");
            } else {
                // 女
                vo.setSex("2");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherName())){
            if (vo.getFatherName().equals(vo.getFullName())) {
                throw new AppException("父亲（监护人）姓名不能与学生姓名相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getMotherName())){
            if (vo.getMotherName().equals(vo.getFullName())) {
                throw new AppException("母亲姓名不能与学生姓名相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherName())&&StringUtils.isNotBlank(vo.getMotherName())){
            if (vo.getMotherName().equals(vo.getFatherName())) {
                throw new AppException("父亲（监护人）姓名不能与母亲姓名相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherIdcard())&&StringUtils.isNotBlank(vo.getMotherIdcard())){
            if (vo.getFatherIdcard().equals(vo.getMotherIdcard())) {
                throw new AppException("父亲（监护人）证件号码不能与母亲证件号码相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherIdcard())){
            if (vo.getFatherIdcard().equals(vo.getIdcard())) {
                throw new AppException("父亲（监护人）证件号码不能与学生证件号码相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getMotherIdcard())){
            if (vo.getMotherIdcard().equals(vo.getIdcard())) {
                throw new AppException("母亲证件号码不能与学生证件号码相同！");
            }
        }
        //设置年龄
        boolean flag = false;
        if (!ObjectUtils.isEmpty(vo.getMotherIdcard())) {
            if (StringUtils.isBlank(vo.getMotherCardType())) {
                vo.setMotherCardType(CardTypeEnum.idcard.getType());
            }
            vo.setMotherIdcard(vo.getMotherIdcard().trim().toUpperCase());
            if (CardTypeEnum.idcard.getType().equals(vo.getMotherCardType()) && !IdcardUtil.isValidCard(vo.getMotherIdcard())) {
                throw new AppException("母亲身份证有误！");
            }
            if (ObjectUtils.isEmpty(vo.getMotherName())) {
                throw new AppException("母亲姓名不能为空！");
            } else {
                vo.setMotherName(
                        Validator.isChinese(vo.getMotherName())
                                ? vo.getMotherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                : vo.getMotherName().trim());
            }
            if (!ObjectUtils.isEmpty(vo.getMotherCellphone()) && !PhoneUtil.isMobile(vo.getMotherCellphone())) {
                throw new AppException("请输入正确的母亲手机号码！");
            }
            flag = true;
        }
        if (!ObjectUtils.isEmpty(vo.getFatherIdcard())) {
            if (StringUtils.isBlank(vo.getFatherCardType())) {
                vo.setFatherCardType(CardTypeEnum.idcard.getType());
            }
            vo.setFatherIdcard(vo.getFatherIdcard().trim().toUpperCase());
            if (CardTypeEnum.idcard.getType().equals(vo.getFatherCardType()) && !IdcardUtil.isValidCard(vo.getFatherIdcard())) {
                throw new AppException("父亲（监护人）身份证有误！");
            }
            if (ObjectUtils.isEmpty(vo.getFatherName())) {
                throw new AppException("父亲（监护人）姓名不能为空！");
            } else {
                vo.setFatherName(
                        Validator.isChinese(vo.getFatherName())
                                ? vo.getFatherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                : vo.getFatherName().trim());
            }
            if (!ObjectUtils.isEmpty(vo.getFatherCellphone()) && !PhoneUtil.isMobile(vo.getFatherCellphone())) {
                throw new AppException("请输入正确的父亲（监护人）手机号码！");
            }
            flag = true;
        }
        if (!ObjectUtils.isEmpty(vo.getRelationshipIdcard())) {
            if (StringUtils.isBlank(vo.getRelationshipCardType())) {
                vo.setRelationshipCardType(CardTypeEnum.idcard.getType());
            }
            vo.setRelationshipIdcard(vo.getRelationshipIdcard().trim().toUpperCase());
            if (CardTypeEnum.idcard.getType().equals(vo.getRelationshipCardType()) && !IdcardUtil.isValidCard(vo.getRelationshipIdcard())) {
                throw new AppException("监护人身份证有误！");
            }
            if (ObjectUtils.isEmpty(vo.getRelationshipName())) {
                throw new AppException("监护人姓名不能为空！");
            } else {
                vo.setRelationshipName(
                        Validator.isChinese(vo.getRelationshipName())
                                ? vo.getRelationshipName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                : vo.getRelationshipName().trim());
            }
            if (ObjectUtils.isEmpty(vo.getRelationshipType())) {
                throw new AppException("监护人与学生的关系不能为空！");
            }
            if (!ObjectUtils.isEmpty(vo.getCellphone()) && !PhoneUtil.isMobile(vo.getCellphone())) {
                throw new AppException("请输入正确的监护人手机号码！");
            }
            flag = true;
        }
        if (!flag) {
            throw new AppException("父亲（监护人）、母亲至少填写一个");
        }
        if (StringUtils.isNotBlank(vo.getFatherIdcard()) && StringUtils.isNotBlank(vo.getMotherIdcard())) {
            if (vo.getFatherIdcard().equalsIgnoreCase(vo.getMotherIdcard())) {
                throw new AppException("提交的父亲（监护人）和母亲证件号码相同！");
            }
        }
        if (vo.getYear() == null) {

            vo.setYear(eduOperationCacheVO.getYear());
        }

        //年龄设置
        int age = 0;
        if (CardTypeEnum.idcard.getType().equalsIgnoreCase(vo.getCardType())) {
            age = IdcardUtil.getAgeByIdCard(
                    vo.getIdcard(),
                    DateUtil.parse(vo.getYear() + "0901", "yyyyMMdd"));
        } else {
            age = DateUtil.age(DateUtil.parse(vo.getBirthYmd(), "yyyyMMdd"), DateUtil.parse(vo.getYear() + "0901", "yyyyMMdd"));
        }
        vo.setAge(age);
        boolean ageThrowFlag = false;
        if (age >= 6 && age <= 7) {
            vo.setSchoolCategory(SchoolCategoryEnum.PRIMARY.getType());
            if (age == 7) {
                ageThrowFlag = true;
            }
        } else if (age >= 11 && age <= 14) {
            vo.setSchoolCategory(SchoolCategoryEnum.JUNIOR.getType());
        } else {
            if(age<11){
                vo.setSchoolCategory(SchoolCategoryEnum.PRIMARY.getType());
            }else{
                vo.setSchoolCategory(SchoolCategoryEnum.JUNIOR.getType());
            }
            ageThrowFlag = true;
        }
        if (EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            LambdaQueryWrapper<EduStudentEnrollWhite> whiteQuery = new QueryWrapper<EduStudentEnrollWhite>().lambda()
                    .eq(EduStudentEnrollWhite::getIdcard, vo.getIdcard())
                    .eq(EduStudentEnrollWhite::getFullName, vo.getFullName())
                    .eq(EduStudentEnrollWhite::getYear,eduHelper.thisYear());
            if (StringUtils.isBlank(vo.getFileInfo())) {
                throw new AppException("材料信息不能为空");
            }
            if (ageThrowFlag&&eduStudentEnrollWhiteService.count(whiteQuery)<=0) {
                throw new AppException("学生不在适龄年龄段！如果是缓学等特殊情况，请联系将要报名的学校");
            }
        }
        //同学段已录取的不能登记  同年
        QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnroll::getIdcard, vo.getIdcard())
                .eq(EduStudentEnroll::getYear,vo.getYear())
                .eq(EduStudentEnroll::getSchoolCategory, vo.getSchoolCategory())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType());
        if (eduStudentEnrollService.count(queryWrapper) > 0) {
            throw new AppException(vo.getFullName() + "已报名录取，不需要登记，如有疑问请联系教育局工作人员");
        }
    }


    @Override
    @OpApi(funcCode = "edustudentenrollpre0021", title = "根据学生idCard查询预采集信息", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public EduStudentEnrollPreVO getStudentEnrollPreByIdCard(EduStudentEnrollPreQueryVO vo) {
        if (ObjectUtils.isEmpty(vo.getYear())) {
            Integer year = operationCacheIntegration.getPeriodYear().getYear();
            vo.setYear(year);
        }
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(EduStudentEnrollPre::getIdcard, vo.getIdcard())
                .eq(EduStudentEnrollPre::getYear, vo.getYear());

        List<EduStudentEnrollPre> enrollPreList = eduStudentEnrollPreService.list(queryWrapper);
        EduStudentEnrollPre enrollPre = new EduStudentEnrollPre();
        if (!CollectionUtils.isEmpty(enrollPreList)) {
            enrollPre = enrollPreList.get(0);
        }
        EduStudentEnrollPreVO enrollPreVO = Convert.convert(EduStudentEnrollPreVO.class, enrollPre);
        return enrollPreVO;
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0022", title = "校验学生年龄是否符合", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE)
    public Boolean checkAge(CheckAgeVO vo) {
        int year = eduHelper.thisYear();
        //年龄设置
        int age = 0;
        if (CardTypeEnum.idcard.getType().equalsIgnoreCase(vo.getCardType())) {
            if (!IdcardUtil.isValidCard(vo.getIdcard())) {
                throw new AppException("学生身份证号码有误");
            }
            age = IdcardUtil.getAgeByIdCard(
                    vo.getIdcard(),
                    DateUtil.parse(year
                            + "0901", "yyyyMMdd"));
        } else {
            if (StringUtils.isBlank(vo.getBirthYmd())) {
                throw new AppException("出生日期不能为空");
            }
            String birthday = "";
            if (vo.getBirthYmd().length() >= 8) {
                birthday = vo.getBirthYmd().replaceAll("-", "").replaceAll("/", "");
            } else if (vo.getBirthYmd().length() == 6) {
                birthday = vo.getBirthYmd() + "01";
            } else {
                throw new AppException("学生出生日期格式不正确");
            }
            age = DateUtil.age(DateUtil.parse(birthday, "yyyyMMdd"), DateUtil.parse(year + "0901", "yyyyMMdd"));
        }
        //准新生登记
        LambdaQueryWrapper<EduBusiEnrollPre> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EduBusiEnrollPre::getIdcard, vo.getIdcard()).eq(EduBusiEnrollPre::getYear, year)
                .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NODO.getType());
        if (eduBusiEnrollPreService.count(queryWrapper) > 0) {
            throw new AppException("该学生信息已登记，处于待审核状态，请耐心等待工作人员审核");
        }

        //新增校验
        //判断学生信息是否存在
        LambdaQueryWrapper<EduStudentEnrollPre> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(EduStudentEnrollPre::getIdcard, vo.getIdcard()).eq(EduStudentEnrollPre::getYear, year);
        if (eduStudentEnrollPreService.count(queryWrapper1) > 0) {
            throw new AppException("该学生信息已存在,不能重复登记");
        }
        if (age >= 6 && age <= 7) {
            return true;
        } else if (age >= 11 && age <= 14) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0023", title = "单个一次准新生登记或修改", funcType = FuncTypeEnum.edit)
    public void unLock(EduStudentEnrollPreKeyVO vo) {
        EduBusiEnrollPre eduBusiEnrollPre = eduBusiEnrollPreService.getById(vo.getBusiEnrollPreId());
        if (eduBusiEnrollPre == null) {
            throw new AppException("未找到需要解锁的数据");
        }
        if (AuthStatusEnum.BH.getType().equalsIgnoreCase(eduBusiEnrollPre.getAuthStatus())) {
            throw new AppException("该数据已做过解锁处理，请刷新页面");
        }
        if (!AuthStatusEnum.NO.getType().equalsIgnoreCase(eduBusiEnrollPre.getAuthStatus())) {
            throw new AppException("只有审核不通过数据才能解锁");
        }
        eduBusiEnrollPre.setAuthStatus(AuthStatusEnum.BH.getType());
        eduBusiEnrollPreService.updateById(eduBusiEnrollPre);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0024", title = "批量解锁一次准新生登记或修改", funcType = FuncTypeEnum.edit)
    public void unLock(AreaControlVO baseVO) {
        if (StringUtils.isBlank(baseVO.getAreaCode())) {
            //获取操作人员行政区划
            baseVO.setAreaCode(SessionUtil.getAreaCode());
        }
        if (StringUtils.isBlank(baseVO.getAreaCode())) {
            //获取当前部署行政区划
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode = commonIntegration.getValueByKey(commonVO);
            if (StringUtils.isBlank(areaCode)) {
                throw new AppException("系统参数中当前部署行政区划不能为空");
            }
            baseVO.setAreaCode(areaCode);
        }
        eduBusiEnrollPreService.unLock(baseVO);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0025", title = "获取出生证比对状态异常的数据", funcType = FuncTypeEnum.query)
    public PageInfo<EduStudentEnrollPreVO> getFamilyFlagList(EduStudentEnrollPreQueryVO vo) {

        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(1000);
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        if (StringUtils.isBlank(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getSessionInfo().getAreaCode());
        }
        String orgId = SessionUtil.getSessionInfo().getOrgId();

        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper.lambda()
                .eq(EduStudentEnrollPre::getAreaCode, vo.getAreaCode())
                .eq(EduStudentEnrollPre::getYear, vo.getYear())
                .eq(EduStudentEnrollPre::getOrgId, orgId)
                .eq(!ObjectUtils.isEmpty(vo.getFullName()), EduStudentEnrollPre::getFullName, vo.getFullName())
                .eq(!ObjectUtils.isEmpty(vo.getIdcard()), EduStudentEnrollPre::getIdcard, vo.getIdcard())
                .eq(!ObjectUtils.isEmpty(vo.getFatherName()), EduStudentEnrollPre::getFatherName, vo.getFatherName())
                .eq(!ObjectUtils.isEmpty(vo.getFatherIdcard()), EduStudentEnrollPre::getFatherIdcard, vo.getFatherIdcard())
                .eq(!ObjectUtils.isEmpty(vo.getMotherName()), EduStudentEnrollPre::getMotherName, vo.getMotherName())
                .eq(!ObjectUtils.isEmpty(vo.getMotherIdcard()), EduStudentEnrollPre::getMotherIdcard, vo.getMotherIdcard())
                .in(EduStudentEnrollPre::getFamilyFlag, 2, 3, 4);


        List<EduStudentEnrollPre> list = eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        // 不为空则获取分页结果
        PageInfo<EduStudentEnrollPre> pageInfo = new PageInfo<>(list);
        // 返回参数需要通过common层的vo实体类，用该方法可以批量转换
        List<EduStudentEnrollPreVO> resultList = Convert.toList(EduStudentEnrollPreVO.class, pageInfo.getList());
        // 转义数据字典值
        dictHelper.valueToName(resultList, Arrays.asList(EduEnrollPreDictEnum.values()));
        return PagerUtil.parsePagerVo(resultList, pageInfo);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0026", title = "修改家庭关系比对状态", funcType = FuncTypeEnum.edit)
    public void updateFamilyFlag(EduStudentEnrollPreQueryVO vo) {
        if (StringUtils.isBlank(vo.getStudentEnrollPreId())) {
            throw new AppException("预采集id不能为空");
        }
        EduStudentEnrollPre studentEnrollPre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        studentEnrollPre.setFamilyFlag(vo.getFamilyFlag());
        studentEnrollPre.setFamilyRemark("学校线下确认");
        eduStudentEnrollPreService.updateById(studentEnrollPre);
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0027", title = "家长端我的申请记录", funcType = FuncTypeEnum.query)
    public List<MyApplyVO> getMyApplyList(BaseVO baseVO) {
        String idcard = SessionUtil.getSessionInfo() == null ? null : SessionUtil.getSessionInfo().getIdcard();
        if (StringUtils.isBlank(idcard)) {
            throw new AppException("用户的证件号码不能为空");
        }
        String key = idcard;
        Cache<String, List<MyApplyVO>> cache = JetCacheUtils.create(EduCache.EDU_MY_APPLY, CacheType.BOTH, Duration.ofHours(2), Duration.ofSeconds(20));
        List<MyApplyVO> value = cache.get(key);
        if (value != null) {
            return value;
        }
        List<MyApplyVO> list = new ArrayList<>();
        Integer year = eduHelper.thisYear();
        //查询当前年度信息登记和修改信息
        QueryWrapper<EduBusiEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(EduBusiEnrollPre::getFullName, EduBusiEnrollPre::getIdcard, EduBusiEnrollPre::getRemarks, EduBusiEnrollPre::getCreateTime, EduBusiEnrollPre::getAuthStatus, EduBusiEnrollPre::getAuthRemarks, EduBusiEnrollPre::getAuthTime, EduBusiEnrollPre::getYear)
                .eq(EduBusiEnrollPre::getYear, year)
                .eq(EduBusiEnrollPre::getSubmitterId, SessionUtil.getUserId())
                .orderByDesc(EduBusiEnrollPre::getCreateTime);
        List<EduBusiEnrollPre> preList = eduBusiEnrollPreService.list(queryWrapper);
        if (!CollectionUtils.isEmpty(preList)) {
            for (EduBusiEnrollPre pre : preList) {
                MyApplyVO myApplyVO = Convert.convert(MyApplyVO.class, pre);
                myApplyVO.setOperationName("子女信息登记/修改");
                if (AuthStatusEnum.YES.getType().equalsIgnoreCase(myApplyVO.getAuthStatus())) {
                    myApplyVO.setAuthStatusName("审核通过");
                } else if (AuthStatusEnum.NO.getType().equalsIgnoreCase(myApplyVO.getAuthStatus())) {
                    myApplyVO.setAuthStatusName("审核不通过");
                } else {
                    myApplyVO.setAuthStatusName("待审核");
                }
                list.add(myApplyVO);
            }
        }
        //查询当前年度人才登记和修改
        QueryWrapper<EduTalent> talentQueryWrapper = new QueryWrapper<>();
        talentQueryWrapper.lambda().select(EduTalent::getFullName, EduTalent::getIdcard, EduTalent::getYear, EduTalent::getAuthRemarks, EduTalent::getAuthStatus, EduTalent::getAuthTime, EduTalent::getStudyIntention, EduTalent::getCreateTime)
                .eq(EduTalent::getYear, year)
                .eq(EduTalent::getCreateName, SessionUtil.getUserId())
                .orderByDesc(EduTalent::getCreateTime);
        List<EduTalent> talentList = eduTalentService.list(talentQueryWrapper);
        if (!CollectionUtils.isEmpty(talentList)) {
            for (EduTalent talent : talentList) {
                MyApplyVO myApplyVO = Convert.convert(MyApplyVO.class, talent);
                myApplyVO.setOperationName("人才子女就读申请");
                myApplyVO.setRemarks(talent.getStudyIntention());
                if (AuthStatusEnum.YES.getType().equalsIgnoreCase(myApplyVO.getAuthStatus())) {
                    myApplyVO.setAuthStatusName("审核通过");
                } else if (AuthStatusEnum.NO.getType().equalsIgnoreCase(myApplyVO.getAuthStatus())) {
                    myApplyVO.setAuthStatusName("审核不通过");
                } else if (AuthStatusEnum.BH.getType().equalsIgnoreCase(myApplyVO.getAuthStatus())) {
                    myApplyVO.setAuthStatusName("审核不通过");
                } else {
                    myApplyVO.setAuthStatusName("待审核");
                }
                list.add(myApplyVO);
            }
        }
        if (!CollectionUtils.isEmpty(list)) {
            list = list.stream().sorted(Comparator.comparing(MyApplyVO::getCreateTime).reversed()).collect(Collectors.toList());
        }
        cache.put(key, list);
        return list;
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0028", title = "家长端学生信息登记保存（业务表）", funcType = FuncTypeEnum.insert)
    @SaveOplog(
            operationType = "edustudentenrollpre0028",
            operationName = "家长端学生信息登记保存（业务表）",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO saveStudentInfoByAPP(EduStudentEnrollPreVO vo) {
        vo.setEnrollPreType(EnrollPreTypeEnum.dj.getType());
        vo.setManagerFlag(false);
        if (!ObjectUtils.isEmpty(vo.getBusiEnrollPreId())) {
            return this.editBusiStudentPre(vo);
        } else {
            return this.addBusiStudentPre(vo);
        }
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0029", title = "管理员端学生信息登记保存（结果表）", funcType = FuncTypeEnum.update)
    @SaveOplog(
            operationType = "edustudentenrollpre0029",
            operationName = "管理员端学生信息登记保存（结果表）",
            dataType = "studentEnrollPreId",
            auType = AuTypeEnum.OTHER)
    @Transactional
    public EduStudentEnrollPreVO saveStudentInfoByAdmin(EduStudentEnrollPreVO vo) {
        String studentEnrollPreId = vo.getStudentEnrollPreId();
        Long busiEnrollPreId = vo.getBusiEnrollPreId();
        if (ObjectUtils.isEmpty(studentEnrollPreId)) {
            throw new AppException("传入需要修改的结果主键不能为空!");
        }
        if (ObjectUtils.isEmpty(busiEnrollPreId)) {
            throw new AppException("传入需要修改的业务主键不能为空!");
        }
        EduBusiEnrollPre busiEnrollPre = eduBusiEnrollPreService.getById(vo.getBusiEnrollPreId());
        if (ObjectUtils.isEmpty(busiEnrollPre)){
            throw new AppException("数据有误，请刷新后重试!");
        }
        vo.setType(SaveTypeEnum.UPDATE.getType());
        vo.setManagerFlag(true);
        EduStudentEnrollPre studentEnrollPre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        if (ObjectUtils.isEmpty(studentEnrollPre)){
            this.editBusiStudentPre(vo);
        }else{
            this.edit(vo);
        }
        return vo;
    }

    @Override
    @OpApi(funcCode = "edustudentenrollpre0030", title = "管理员端重置获取大数据", funcType = FuncTypeEnum.query)
    public void resetBigData(ResetBigDataVO vo) {
        String key=EduCache.APP_NAME+"resetBigData";
        if (redisHelper.hasKey(key)) {
            throw new AppException("正在执行中.....");
        }
        redisHelper.set(key, "1", 60);
        try {
            if ("hj".equalsIgnoreCase(vo.getType())) {
                eduStudentEnrollPreService.resetHjSyncStatus(vo.getYear(), vo.getAreaCode());
            } else if ("fc".equalsIgnoreCase(vo.getType())) {
                eduStudentEnrollPreService.resetFcSyncStatus(vo.getYear(), vo.getAreaCode());
            } else if ("cb".equalsIgnoreCase(vo.getType())) {
                eduStudentEnrollPreService.resetCbSyncStatus(vo.getYear(), vo.getAreaCode());
            } else if ("jzz".equalsIgnoreCase(vo.getType())) {
                eduStudentEnrollPreService.resetJzzSyncStatus(vo.getYear(), vo.getAreaCode());
            }
        }catch (Exception e){
            throw new AppException(e.getMessage(),e);
        }finally {
            redisHelper.del(key);
        }
    }
    @OpApi(funcCode = "edustudentenrollpre0031", title = "管理员端重置预报名状态", funcType = FuncTypeEnum.query)
    public void resetYbm(ResetBigDataVO vo) {
        String key=EduCache.APP_NAME+"resetBeforeFlag";
        if (redisHelper.hasKey(key)) {
            throw new AppException("正在执行中.....");
        }
        redisHelper.set(key, "1", 60);
        try {
            eduStudentEnrollPreService.resetBeforeFlag(vo.getYear(),vo.getSchoolCategory(),vo.getAreaCode());
        }catch (Exception e){
            throw new AppException(e.getMessage(),e);
        }finally {
            redisHelper.del(key);
        }
    }
    /**
     * 家长端学生信息添加（业务表）
     *
     * @param vo
     * @return
     */
    private EduStudentEnrollPreVO addBusiStudentPre(EduStudentEnrollPreVO vo) {
        checkBusiStudent(vo);
        //判断参数是否有结果表id
        if (StringUtils.isBlank(vo.getStudentEnrollPreId())) {
            vo.setStudentEnrollPreId(IdUtil.simpleUUID());
        }
        if (StringUtils.isNotBlank(vo.getSchoolId())) {
            EduSchoolVO school = eduSchoolService.getDetail(vo.getSchoolId());
            if (school != null) {
                vo.setShortName(school.getShortName());
            }
        }
        vo.setAuthStatus(AuthStatusEnum.NODO.getType());
        vo.setAuthRemarks(null);
        vo.setAuthTime(null);
        vo.setAuthUserId(null);
        EduBusiEnrollPre eduBusiEnrollPre = Convert.convert(EduBusiEnrollPre.class, vo);
        eduBusiEnrollPreService.save(eduBusiEnrollPre);
        //清除缓存
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(eduBusiEnrollPre.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCachePreBefore(eduBusiEnrollPre.getStudentEnrollPreId());
        eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyApply(eduBusiEnrollPre.getMotherIdcard());
        return vo;
    }


    /**
     * 家长端学生信息修改（业务表）
     *
     * @param vo
     * @return
     */
    private EduStudentEnrollPreVO editBusiStudentPre(EduStudentEnrollPreVO vo) {
        Long busiEnrollPreId = vo.getBusiEnrollPreId();
        if (ObjectUtils.isEmpty(busiEnrollPreId)) {
            throw new AppException("传入需要修改的主键不能为空!");
        }
        checkBusiStudent(vo);
        EduBusiEnrollPre busiEnrollPre = eduBusiEnrollPreService.getById(busiEnrollPreId);
        if (ObjectUtils.isEmpty(busiEnrollPre)) {
            throw new AppException("数据有误，请刷新后重试！!");
        }

        if (!EnrollPreTypeEnum.gl.getType().equals(vo.getEnrollPreType())) {
            if (!busiEnrollPre.getAuthStatus().equals(AuthStatusEnum.NODO.getType())) {
                throw new AppException("只能修改待审核数据！");
            }
        }
        UpdateWrapper<EduBusiEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda()
                .eq(EduBusiEnrollPre::getBusiEnrollPreId, vo.getBusiEnrollPreId())
                .set(EduBusiEnrollPre::getIdcard, vo.getIdcard())
                .set(EduBusiEnrollPre::getCardType, vo.getCardType())
                .set(EduBusiEnrollPre::getFullName, vo.getFullName())
                .set(EduBusiEnrollPre::getFatherName, vo.getFatherName())
                .set(EduBusiEnrollPre::getFatherCardType, vo.getFatherCardType())
                .set(EduBusiEnrollPre::getFatherIdcard, vo.getFatherIdcard())
                .set(EduBusiEnrollPre::getMotherName, vo.getMotherName())
                .set(EduBusiEnrollPre::getMotherCardType, vo.getMotherCardType())
                .set(EduBusiEnrollPre::getMotherIdcard, vo.getMotherIdcard())
                .set(EduBusiEnrollPre::getRemarks, vo.getRemarks())
                .set(EduBusiEnrollPre::getFileInfo, vo.getFileInfo())
                .set(!ObjectUtils.isEmpty(vo.getFatherCellphone()),EduBusiEnrollPre::getFatherCellphone,vo.getFatherCellphone())
                .set(!ObjectUtils.isEmpty(vo.getFatherWork()),EduBusiEnrollPre::getFatherWork,vo.getFatherWork())
                .set(!ObjectUtils.isEmpty(vo.getMotherCardType()),EduBusiEnrollPre::getMotherCellphone,vo.getMotherCellphone())
                .set(!ObjectUtils.isEmpty(vo.getMotherWork()),EduBusiEnrollPre::getMotherWork,vo.getMotherWork())
                .set(!ObjectUtils.isEmpty(vo.getAddress()),EduBusiEnrollPre::getAddress,vo.getAddress())
                .set(!ObjectUtils.isEmpty(vo.getHouseholdPlace()),EduBusiEnrollPre::getHouseholdPlace,vo.getHouseholdPlace())
                .set(EduBusiEnrollPre::getUpdateName, SessionUtil.getUserId())
                .set(EduBusiEnrollPre::getUpdateTime, new Date());
        eduBusiEnrollPreService.update(updateWrapper);
        //清除缓存
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(busiEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(busiEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyEnrollPre(busiEnrollPre.getMotherIdcard());
        eduEnrollClearCacheHelper.clearCachePreBefore(busiEnrollPre.getStudentEnrollPreId());
        eduEnrollClearCacheHelper.clearCacheMyApply(busiEnrollPre.getIdcard());
        eduEnrollClearCacheHelper.clearCacheMyApply(busiEnrollPre.getFatherIdcard());
        eduEnrollClearCacheHelper.clearCacheMyApply(busiEnrollPre.getMotherIdcard());
        return vo;
    }

    private void checkBusiStudent(EduStudentEnrollPreVO vo) {
        if (ObjectUtils.isEmpty(vo.getEnrollPreType())) {
            throw new AppException("预采集类型不能为空！");
        }
        if (vo.getManagerFlag()) {
            List<EduStudentEnrollFamilyVO> familyList = vo.getFamilyList();
            boolean flag = false;
            if (!CollectionUtils.isEmpty(familyList)) {
                Map<String, Integer> cfMap = new HashMap<>();
                for (EduStudentEnrollFamilyVO eduStudentEnrollFamilyVO : familyList) {
                    if (cfMap.get(eduStudentEnrollFamilyVO.getRelationshipType()) == null) {
                        cfMap.put(eduStudentEnrollFamilyVO.getRelationshipType(), 1);
                    } else {
                        throw new AppException("监护人" + RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()) != null ? RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()).getName() : "" + "重复");
                    }
                    if (RelationTypeEnum.father.getType().equals(eduStudentEnrollFamilyVO.getRelationshipType())) {
                        if (StringUtils.isBlank(eduStudentEnrollFamilyVO.getCardType())) {
                            eduStudentEnrollFamilyVO.setCardType(CardTypeEnum.idcard.getType());
                        }
                        vo.setFatherName(eduStudentEnrollFamilyVO.getFullName());
                        vo.setFatherCardType(eduStudentEnrollFamilyVO.getCardType());
                        vo.setFatherIdcard(eduStudentEnrollFamilyVO.getIdcard());
                        vo.setFatherWork(eduStudentEnrollFamilyVO.getWork());
                        vo.setFatherCellphone(eduStudentEnrollFamilyVO.getCellphone());

                        if (CardTypeEnum.idcard.getType().equals(vo.getFatherCardType()) && !IdcardUtil.isValidCard(vo.getFatherIdcard())) {
                            throw new AppException("父亲身份证有误！");
                        }
                        if (ObjectUtils.isEmpty(vo.getFatherName()) || ObjectUtils.isEmpty(vo.getFatherName().trim())) {
                            throw new AppException("父亲姓名不能为空！");
                        } else {
                            vo.setFatherName(
                                    Validator.isChinese(vo.getFatherName())
                                            ? vo.getFatherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                            : vo.getFatherName().trim());
                        }
                        if (!ObjectUtils.isEmpty(vo.getFatherCellphone()) && !PhoneUtil.isMobile(vo.getFatherCellphone())) {
                            throw new AppException("请输入正确的父亲手机号码！");
                        }
                        flag = true;
                    } else if (RelationTypeEnum.mother.getType().equals(eduStudentEnrollFamilyVO.getRelationshipType())) {
                        if (StringUtils.isBlank(eduStudentEnrollFamilyVO.getCardType())) {
                            eduStudentEnrollFamilyVO.setCardType(CardTypeEnum.idcard.getType());
                        }
                        vo.setMotherName(eduStudentEnrollFamilyVO.getFullName());
                        vo.setMotherCardType(eduStudentEnrollFamilyVO.getCardType());
                        vo.setMotherIdcard(eduStudentEnrollFamilyVO.getIdcard());
                        vo.setMotherWork(eduStudentEnrollFamilyVO.getWork());
                        vo.setMotherCellphone(eduStudentEnrollFamilyVO.getCellphone());
                        if (CardTypeEnum.idcard.getType().equals(vo.getMotherCardType()) && !IdcardUtil.isValidCard(vo.getMotherIdcard())) {
                            throw new AppException("母亲身份证有误！");
                        }
                        if (ObjectUtils.isEmpty(vo.getMotherName()) || ObjectUtils.isEmpty(vo.getMotherName().trim())) {
                            throw new AppException("母亲姓名不能为空！");
                        } else {
                            vo.setMotherName(
                                    Validator.isChinese(vo.getMotherName())
                                            ? vo.getMotherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                            : vo.getMotherName().trim());
                        }
                        if (!ObjectUtils.isEmpty(vo.getMotherCellphone()) && !PhoneUtil.isMobile(vo.getMotherCellphone())) {
                            throw new AppException("请输入正确的母亲手机号码！");
                        }
                        flag = true;
                    } else {
                        if (StringUtils.isBlank(eduStudentEnrollFamilyVO.getCardType())) {
                            eduStudentEnrollFamilyVO.setCardType(CardTypeEnum.idcard.getType());
                        }
                        vo.setRelationshipName(eduStudentEnrollFamilyVO.getFullName());
                        vo.setRelationshipCardType(eduStudentEnrollFamilyVO.getCardType());
                        vo.setWork(eduStudentEnrollFamilyVO.getWork());
                        vo.setCellphone(eduStudentEnrollFamilyVO.getCellphone());
                        vo.setRelationshipType(eduStudentEnrollFamilyVO.getRelationshipType());
                        vo.setRelationshipIdcard(eduStudentEnrollFamilyVO.getIdcard().trim().toUpperCase());
                        String reType = RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()) != null ? RelationTypeEnum.getByType(eduStudentEnrollFamilyVO.getRelationshipType()).getName() : "";
                        if (CardTypeEnum.idcard.getType().equals(vo.getRelationshipCardType()) && !IdcardUtil.isValidCard(vo.getRelationshipIdcard())) {
                            throw new AppException("监护人" + reType + "身份证有误！");
                        }
                        if (ObjectUtils.isEmpty(vo.getRelationshipName()) || ObjectUtils.isEmpty(vo.getRelationshipName().trim())) {
                            throw new AppException("监护人" + reType + "姓名不能为空！");
                        } else {
                            vo.setRelationshipName(
                                    Validator.isChinese(vo.getRelationshipName())
                                            ? vo.getRelationshipName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                            : vo.getRelationshipName().trim());
                        }
                        if (!ObjectUtils.isEmpty(vo.getCellphone()) && !PhoneUtil.isMobile(vo.getCellphone())) {
                            throw new AppException("请输入正确的监护人" + reType + "手机号码！");
                        }
                    }
                }
                if (!flag) {
                    vo.setFatherName(vo.getRelationshipName());
                    vo.setFatherCardType(vo.getRelationshipCardType());
                    vo.setFatherIdcard(vo.getRelationshipIdcard());
                    vo.setFatherWork(vo.getWork());
                    vo.setFatherCellphone(vo.getCellphone());
                }
            }
        }
        if (StringUtils.isBlank(vo.getAreaCode())) {
            if (!EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
                SessionInfo sessionInfo = SessionUtil.getSessionInfo();
                if (sessionInfo != null) {
                    vo.setAreaCode(sessionInfo.getAreaCode());
                    vo.setAreaName(sessionInfo.getAreaName());
                }
            } else {
                throw new AppException("家长端登记或修改行政区划不能为空");
            }
        }
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setClassify("2");
        EduOperationCacheVO eduOperationCacheVO = eduSystemConfigIntegration.getEduOperation(queryVO);
        //TODO 判断是否在经办业务期内

        if (StringUtils.isBlank(vo.getCardType())) {
            vo.setCardType(CardTypeEnum.idcard.getType());
        }
        if (StringUtils.isBlank(vo.getIdcard())) {
            throw new AppException("学生证件号码不能为空");
        }
        vo.setIdcard(vo.getIdcard().trim().toUpperCase());
        if (CardTypeEnum.idcard.getType().equals(vo.getCardType()) && !IdcardUtil.isValidCard(vo.getIdcard())) {
            throw new AppException("学生身份证号码有误");
        }
        if (ObjectUtils.isEmpty(vo.getFullName())) {
            throw new AppException("学生姓名不能为空！");
        } else {
            vo.setFullName(
                    Validator.isChinese(vo.getFullName())
                            ? vo.getFullName().replaceAll(" ", "").replaceAll(" ", "").trim()
                            : vo.getFullName().trim());
        }
        if (!CardTypeEnum.idcard.getType().equals(vo.getCardType())) {
            if (StringUtils.isBlank(vo.getSex())) {
                throw new AppException("学生性别不能为空！");
            }
            if (StringUtils.isBlank(vo.getBirthYmd())) {
                throw new AppException("学生出生日期不能为空！");
            }
            String birthday = "";
            if (vo.getBirthYmd().length() >= 8) {
                birthday = vo.getBirthYmd().replaceAll("-", "").replaceAll("/", "");
            } else if (vo.getBirthYmd().length() == 6) {
                birthday = vo.getBirthYmd() + "01";
            } else {
                throw new AppException("学生出生日期格式不正确");
            }
            vo.setBirthYmd(birthday);
        } else {
            vo.setBirthYmd(IdcardUtil.getBirth(vo.getIdcard()));
            int gender = IdcardUtil.getGenderByIdCard(vo.getIdcard());
            if (gender == 1) {
                // 男
                vo.setSex("1");
            } else {
                // 女
                vo.setSex("2");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherName())){
            if (vo.getFatherName().equals(vo.getFullName())) {
                throw new AppException("父亲（监护人）姓名不能与学生姓名相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getMotherName())){
            if (vo.getMotherName().equals(vo.getFullName())) {
                throw new AppException("母亲姓名不能与学生姓名相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherName())&&StringUtils.isNotBlank(vo.getMotherName())){
            if (vo.getMotherName().equals(vo.getFatherName())) {
                throw new AppException("父亲（监护人）姓名不能与母亲姓名相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherIdcard())&&StringUtils.isNotBlank(vo.getMotherIdcard())){
            if (vo.getFatherIdcard().equals(vo.getMotherIdcard())) {
                throw new AppException("父亲（监护人）证件号码不能与母亲证件号码相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getFatherIdcard())){
            if (vo.getFatherIdcard().equals(vo.getIdcard())) {
                throw new AppException("父亲（监护人）证件号码不能与学生证件号码相同！");
            }
        }
        if(StringUtils.isNotBlank(vo.getMotherIdcard())){
            if (vo.getMotherIdcard().equals(vo.getIdcard())) {
                throw new AppException("母亲证件号码不能与学生证件号码相同！");
            }
        }
        //设置年龄
        boolean flag = false;
        if (!ObjectUtils.isEmpty(vo.getMotherIdcard())) {
            if (StringUtils.isBlank(vo.getMotherCardType())) {
                vo.setMotherCardType(CardTypeEnum.idcard.getType());
            }
            vo.setMotherIdcard(vo.getMotherIdcard().trim().toUpperCase());
            if (CardTypeEnum.idcard.getType().equals(vo.getMotherCardType()) && !IdcardUtil.isValidCard(vo.getMotherIdcard())) {
                throw new AppException("母亲身份证有误！");
            }
            if (ObjectUtils.isEmpty(vo.getMotherName())) {
                throw new AppException("母亲姓名不能为空！");
            } else {
                vo.setMotherName(
                        Validator.isChinese(vo.getMotherName())
                                ? vo.getMotherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                : vo.getMotherName().trim());
            }
            if (!ObjectUtils.isEmpty(vo.getMotherCellphone()) && !PhoneUtil.isMobile(vo.getMotherCellphone())) {
                throw new AppException("请输入正确的母亲手机号码！");
            }
            flag = true;
        }
        if (!ObjectUtils.isEmpty(vo.getFatherIdcard())) {
            if (StringUtils.isBlank(vo.getFatherCardType())) {
                vo.setFatherCardType(CardTypeEnum.idcard.getType());
            }
            vo.setFatherIdcard(vo.getFatherIdcard().trim().toUpperCase());
            if (CardTypeEnum.idcard.getType().equals(vo.getFatherCardType()) && !IdcardUtil.isValidCard(vo.getFatherIdcard())) {
                throw new AppException("父亲（监护人）身份证有误！");
            }
            if (ObjectUtils.isEmpty(vo.getFatherName())) {
                throw new AppException("父亲（监护人）姓名不能为空！");
            } else {
                vo.setFatherName(
                        Validator.isChinese(vo.getFatherName())
                                ? vo.getFatherName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                : vo.getFatherName().trim());
            }
            if (!ObjectUtils.isEmpty(vo.getFatherCellphone()) && !PhoneUtil.isMobile(vo.getFatherCellphone())) {
                throw new AppException("请输入正确的父亲（监护人）手机号码！");
            }
            flag = true;
        }
        if (!ObjectUtils.isEmpty(vo.getRelationshipIdcard())) {
            if (StringUtils.isBlank(vo.getRelationshipCardType())) {
                vo.setRelationshipCardType(CardTypeEnum.idcard.getType());
            }
            vo.setRelationshipIdcard(vo.getRelationshipIdcard().trim().toUpperCase());
            if (CardTypeEnum.idcard.getType().equals(vo.getRelationshipCardType()) && !IdcardUtil.isValidCard(vo.getRelationshipIdcard())) {
                throw new AppException("监护人身份证有误！");
            }
            if (ObjectUtils.isEmpty(vo.getRelationshipName())) {
                throw new AppException("监护人姓名不能为空！");
            } else {
                vo.setRelationshipName(
                        Validator.isChinese(vo.getRelationshipName())
                                ? vo.getRelationshipName().replaceAll(" ", "").replaceAll(" ", "").trim()
                                : vo.getRelationshipName().trim());
            }
            if (ObjectUtils.isEmpty(vo.getRelationshipType())) {
                throw new AppException("监护人与学生的关系不能为空！");
            }
            if (!ObjectUtils.isEmpty(vo.getCellphone()) && !PhoneUtil.isMobile(vo.getCellphone())) {
                throw new AppException("请输入正确的监护人手机号码！");
            }
            flag = true;
        }
        if (!flag) {
            throw new AppException("父亲（监护人）、母亲至少填写一个");
        }
        if (StringUtils.isNotBlank(vo.getFatherIdcard()) && StringUtils.isNotBlank(vo.getMotherIdcard())) {
            if (vo.getFatherIdcard().equalsIgnoreCase(vo.getMotherIdcard())) {
                throw new AppException("提交的父亲（监护人）和母亲证件号码相同！");
            }
        }
        if (vo.getYear() == null) {

            vo.setYear(eduOperationCacheVO.getYear());
        }

        //年龄设置
        int age = 0;
        if (CardTypeEnum.idcard.getType().equalsIgnoreCase(vo.getCardType())) {
            age = IdcardUtil.getAgeByIdCard(
                    vo.getIdcard(),
                    DateUtil.parse(vo.getYear() + "0901", "yyyyMMdd"));
        } else {
            age = DateUtil.age(DateUtil.parse(vo.getBirthYmd(), "yyyyMMdd"), DateUtil.parse(vo.getYear() + "0901", "yyyyMMdd"));
        }
        vo.setAge(age);
        boolean ageThrowFlag = false;
        if (age >= 6 && age <= 7) {
            vo.setSchoolCategory(SchoolCategoryEnum.PRIMARY.getType());
            if (age == 7) {
                ageThrowFlag = true;
            }
        } else if (age >= 11 && age <= 14) {
            vo.setSchoolCategory(SchoolCategoryEnum.JUNIOR.getType());
        } else {
            ageThrowFlag = true;
        }
        if (!vo.getManagerFlag() && EnrollPreTypeEnum.dj.getType().equalsIgnoreCase(vo.getEnrollPreType())) {
            if (StringUtils.isBlank(vo.getFileInfo())) {
                throw new AppException("材料信息不能为空");
            }
            if (ageThrowFlag) {
                throw new AppException("学生不在适龄年龄段！如果是缓学等特殊情况，请联系将要报名的学校");
            }
        }
        //同学段已录取的不能登记
        QueryWrapper<EduStudentEnroll> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnroll::getIdcard, vo.getIdcard())
                .eq(EduStudentEnroll::getYear,vo.getYear())
                .eq(EduStudentEnroll::getSchoolCategory, vo.getSchoolCategory())
                .eq(EduStudentEnroll::getEnrollStatus, EnrollStatusFormalEnum.lq.getType());
        if (eduStudentEnrollService.count(queryWrapper) > 0) {
            throw new AppException(vo.getFullName() + "已报名录取，不需要登记，如有疑问请联系教育局工作人员");
        }
        String userId = SessionUtil.getUserId();
        String fullName = SessionUtil.getFullName();
        String cellphone = SessionUtil.getSessionInfo().getCellphone();

        //如果有结果表中没有数据
        if (ObjectUtils.isEmpty(vo.getStudentEnrollPreId())) {
            vo.setType(SaveTypeEnum.INSERT.getType());
            //判断当前年度是否有待审核数据
            QueryWrapper<EduBusiEnrollPre> busiEnrollQueryWrapper = new QueryWrapper<>();
            busiEnrollQueryWrapper.lambda()
                    .eq(EduBusiEnrollPre::getYear, eduHelper.thisYear())
                    .eq(EduBusiEnrollPre::getIdcard, vo.getIdcard())
                    .eq(EduBusiEnrollPre::getAuthStatus, AuthStatusEnum.NODO);
            if (eduBusiEnrollPreService.count(busiEnrollQueryWrapper) > 0) {
                throw new AppException("该学生信息已登记，处于待审核状态，请耐心等待工作人员审核");
            }
            //新增校验
            //判断学生信息是否存在
            LambdaQueryWrapper<EduStudentEnrollPre> enrollPreLambdaQueryWrapper = new LambdaQueryWrapper<>();
            enrollPreLambdaQueryWrapper.eq(EduStudentEnrollPre::getIdcard, vo.getIdcard()).eq(EduStudentEnrollPre::getYear, vo.getYear());
            if (eduStudentEnrollPreService.count(enrollPreLambdaQueryWrapper) > 0) {
                throw new AppException("该学生信息已存在,不能重复登记");
            }
            vo.setBeforeFlag("0");
            vo.setCalculateFlag("0");
            vo.setHouseholdSyncFlag("0");
            vo.setHouseSyncFlag("0");
            vo.setNetsignSyncFlag("0");
            vo.setCbSyncFlag("0");
            vo.setQySyncFlag("0");
            vo.setFamilyFlag("0");
            vo.setConsistentFlag("0");
            if(StringUtils.isBlank(vo.getConsistentType())){
                vo.setConsistentType("1");
            }
            //就需要新增结果表中的数据
        } else {
            vo.setType(SaveTypeEnum.UPDATE.getType());
        }
        //设置提交人信息
        vo.setSubmitterId(userId);
        vo.setSubmitterName(fullName);
        vo.setTelphone(cellphone);
    }

}
